home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / ispell.el.z / ispell.el
Encoding:
Text File  |  1998-05-21  |  95.1 KB  |  2,503 lines

  1. ;;; ispell.el --- spell checking using Ispell
  2.  
  3. ;; Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
  4.  
  5. ;; Authors         : Ken Stevens <k.stevens@ieee.org>
  6. ;; Syntax          : emacs-lisp
  7. ;; Version       : International Ispell Version 3.1 by Geoff Kuenning.
  8. ;; Bug Reports       : ispell-el-bugs@itcorp.com
  9.  
  10. ;; Note: version numbers and time stamp are not updated
  11. ;;   when this file is edited for release with GNU emacs.
  12.  
  13. ;; This file is part of XEmacs.
  14.  
  15. ;; XEmacs is free software; you can redistribute it and/or modify it
  16. ;; under the terms of the GNU General Public License as published by
  17. ;; the Free Software Foundation; either version 2, or (at your option)
  18. ;; any later version.
  19.  
  20. ;; XEmacs is distributed in the hope that it will be useful, but
  21. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23. ;; General Public License for more details.
  24.  
  25. ;; You should have received a copy of the GNU General Public License
  26. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  27. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  28. ;; 02111-1307, USA.
  29.  
  30. ;;; Commentary:
  31.  
  32. ;; INSTRUCTIONS
  33. ;;
  34. ;;  This code contains a section of user-settable variables that you should
  35. ;; inspect prior to installation.  Look past the end of the history list.
  36. ;; Set them up for your locale and the preferences of the majority of the
  37. ;; users.  Otherwise the users may need to set a number of variables
  38. ;; themselves.
  39. ;;  You particularly may want to change the default dictionary for your
  40. ;; country and language.
  41. ;;
  42. ;;
  43. ;; To fully install this, add this file to your Emacs Lisp directory and
  44. ;; compile it with M-X byte-compile-file.  Then add the following to the
  45. ;; appropriate init file:
  46. ;;
  47. ;;  (autoload 'ispell-word "ispell"
  48. ;;    "Check the spelling of word in buffer." t)
  49. ;;  (global-set-key "\e$" 'ispell-word)
  50. ;;  (autoload 'ispell-region "ispell"
  51. ;;    "Check the spelling of region." t)
  52. ;;  (autoload 'ispell-buffer "ispell"
  53. ;;    "Check the spelling of buffer." t)
  54. ;;  (autoload 'ispell-complete-word "ispell"
  55. ;;    "Look up current word in dictionary and try to complete it." t)
  56. ;;  (autoload 'ispell-change-dictionary "ispell"
  57. ;;    "Change ispell dictionary." t)
  58. ;;  (autoload 'ispell-message "ispell"
  59. ;;    "Check spelling of mail message or news post.")
  60. ;;
  61. ;;  Depending on the mail system you use, you may want to include these:
  62. ;;
  63. ;;  (add-hook 'news-inews-hook 'ispell-message)
  64. ;;  (add-hook 'mail-send-hook  'ispell-message)
  65. ;;  (add-hook 'mh-before-send-letter-hook 'ispell-message)
  66. ;;
  67. ;;
  68. ;; Ispell has a TeX parser and a nroff parser (the default).
  69. ;; The parsing is controlled by the variable ispell-parser.  Currently
  70. ;; it is just a "toggle" between TeX and nroff, but if more parsers are
  71. ;; added it will be updated.  See the variable description for more info.
  72. ;;
  73. ;;
  74. ;; TABLE OF CONTENTS
  75. ;;
  76. ;;   ispell-word
  77. ;;   ispell-region
  78. ;;   ispell-buffer
  79. ;;   ispell-message
  80. ;;   ispell-continue
  81. ;;   ispell-complete-word
  82. ;;   ispell-complete-word-interior-frag
  83. ;;   ispell-change-dictionary
  84. ;;   ispell-kill-ispell
  85. ;;   ispell-pdict-save
  86. ;;
  87. ;;
  88. ;; Commands in ispell-region:
  89. ;; Character replacement: Replace word with choice.  May query-replace.
  90. ;; ' ': Accept word this time.
  91. ;; 'i': Accept word and insert into private dictionary.
  92. ;; 'a': Accept word for this session.
  93. ;; 'A': Accept word and place in buffer-local dictionary.
  94. ;; 'r': Replace word with typed-in value.  Rechecked.
  95. ;; 'R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
  96. ;; '?': Show these commands
  97. ;; 'x': Exit spelling buffer.  Move cursor to original point.
  98. ;; 'X': Exit spelling buffer.  Leave cursor at the current point.
  99. ;; 'q': Quit spelling session (Kills ispell process).
  100. ;; 'l': Look up typed-in replacement in alternate dictionary.  Wildcards okay.
  101. ;; 'u': Like 'i', but the word is lower-cased first.
  102. ;; 'm': Like 'i', but allows one to include dictionary completion info.
  103. ;; 'C-l': redraws screen
  104. ;; 'C-r': recursive edit
  105. ;; 'C-z': suspend emacs or iconify frame
  106. ;;
  107. ;; Buffer-Local features:
  108. ;; There are a number of buffer-local features that can be used to customize
  109. ;;  ispell for the current buffer.  This includes language dictionaries,
  110. ;;  personal dictionaries, parsing, and local word spellings.  Each of these
  111. ;;  local customizations are done either through local variables, or by
  112. ;;  including the keyword and argument(s) at the end of the buffer (usually
  113. ;;  prefixed by the comment characters).  See the end of this file for
  114. ;;  examples.  The local keywords and variables are:
  115. ;;
  116. ;;  ispell-dictionary-keyword   language-dictionary
  117. ;;      uses local variable ispell-local-dictionary
  118. ;;  ispell-pdict-keyword        personal-dictionary
  119. ;;      uses local variable ispell-local-pdict
  120. ;;  ispell-parsing-keyword      mode-arg extended-char-arg
  121. ;;  ispell-words-keyword        any number of local word spellings
  122. ;;
  123. ;;
  124. ;; BUGS:
  125. ;;  Highlighting in version 19 still doesn't work on tty's.
  126. ;;  On some versions of emacs, growing the minibuffer fails.
  127. ;;
  128. ;; HISTORY
  129. ;;
  130. ;; Revision 2.38  1996/5/30    ethanb@phys.washington.edu
  131. ;; Update ispell-message for gnus 5 (news-inews-hook => message-send-hook;
  132. ;; different header for quoted message).
  133. ;;
  134. ;; Revision 2.37  1995/6/13 12:05:28    stevens
  135. ;; Removed autoload from ispell-dictionary-alist. *choices* mode-line shows
  136. ;; misspelled word.  Block skip for pgp & forwarded messages added.
  137. ;; RMS: the autoload changes had problems and I removed them.
  138. ;;
  139. ;; Revision 2.36  1995/2/6 17:39:38    stevens
  140. ;; Properly adjust screen with different ispell-choices-win-default-height
  141. ;; settings.  Skips SGML entity references.
  142. ;;
  143. ;; Revision 2.35  1995/1/13 14:16:46    stevens
  144. ;; Skips SGML tags, ispell-change-dictionary fix for add-hook, assure personal
  145. ;; dictionary is saved when called from the menu
  146. ;;
  147. ;; Revision 2.34  1994/12/08 13:17:41  stevens
  148. ;; Interaction corrected to function with all 3.1 ispell versions.
  149. ;;
  150. ;; Revision 2.33  1994/11/24 02:31:20  stevens
  151. ;; Repaired bug introduced in 2.32 that corrupts buffers when correcting.
  152. ;; Improved buffer scrolling. Nondestructive buffer selections allowed.
  153. ;;
  154. ;; Revision 2.32  1994/10/31 21:10:08  geoff
  155. ;; Many revisions accepted from RMS/FSF.  I think (though I don't know) that
  156. ;; this represents an 'official' version.
  157. ;;
  158. ;; Revision 2.31  1994/5/31 10:18:17  stevens
  159. ;; Repaired comments.  buffer-local commands executed in `ispell-word' now.
  160. ;; German dictionary described for extended character mode.  Dict messages.
  161. ;;
  162. ;; Revision 2.30  1994/5/20 22:18:36  stevens
  163. ;; Continue ispell from ispell-word, C-z functionality fixed.
  164. ;;
  165. ;; Revision 2.29  1994/5/12 09:44:33  stevens
  166. ;; Restored ispell-use-ptys-p, ispell-message aborts sends with interrupt.
  167. ;; defined fn ispell
  168. ;;
  169. ;; Revision 2.28  1994/4/28 16:24:40  stevens
  170. ;; Window checking when ispell-message put on gnus-inews-article-hook jwz.
  171. ;; prefixed ispell- to highlight functions and horiz-scroll fn.
  172. ;; Try and respect case of word in ispell-complete-word.
  173. ;; Ignore non-char events.  Ispell-use-ptys-p commented out. Lucid menu.
  174. ;; Better interrupt handling.  ispell-message improvements from Ethan.
  175. ;;
  176. ;; Revision 2.27
  177. ;; version 18 explicit C-g handling disabled as it didn't work. Added
  178. ;; ispell-extra-args for ispell customization (jwz)
  179. ;;
  180. ;; Revision 2.26  1994/2/15 16:11:14  stevens
  181. ;; name changes for copyright assignment.  Added word-frags in complete-word.
  182. ;; Horizontal scroll (John Conover). Query-replace matches words now.  bugs.
  183. ;;
  184. ;; Revision 2.25
  185. ;; minor mods, upgraded ispell-message
  186. ;;
  187. ;; Revision 2.24
  188. ;; query-replace more robust, messages, defaults, ispell-change-dict.
  189. ;;
  190. ;; Revision 2.23  1993/11/22 23:47:03  stevens
  191. ;; ispell-message, Fixed highlighting, added menu-bar, fixed ispell-help, ...
  192. ;;
  193. ;; Revision 2.22
  194. ;; Added 'u' command.  Fixed default in ispell-local-dictionary.
  195. ;; fixed affix rules display.  Tib skipping more robust.  Contributions by
  196. ;; Per Abraham (parser selection), Denis Howe, and Eberhard Mattes.
  197. ;;
  198. ;; Revision 2.21  1993/06/30 14:09:04  stevens
  199. ;; minor bugs. (nroff word skipping fixed)
  200. ;;
  201. ;; Revision 2.20  1993/06/30 14:09:04  stevens
  202. ;;
  203. ;; Debugging and contributions by: Boris Aronov, Rik Faith, Chris Moore,
  204. ;;  Kevin Rodgers, Malcolm Davis.
  205. ;; Particular thanks to Michael Lipp, Jamie Zawinski, Phil Queinnec
  206. ;;  and John Heidemann for suggestions and code.
  207. ;; Major update including many tweaks.
  208. ;; Many changes were integrations of suggestions.
  209. ;; lookup-words rehacked to use call-process (Jamie).
  210. ;; ispell-complete-word rehacked to be compatible with the rest of the
  211. ;; system for word searching and to include multiple wildcards,
  212. ;; and its own dictionary.
  213. ;; query-replace capability added.  New options 'X', 'R', and 'A'.
  214. ;; buffer-local modes for dictionary, word-spelling, and formatter-parsing.
  215. ;; Many random bugs, like commented comments being skipped, fix to
  216. ;; keep-choices-win, fix for math mode, added pipe mode choice,
  217. ;; fixed 'q' command, ispell-word checks previous word and leave cursor
  218. ;; in same location.  Fixed tib code which could drop spelling regions.
  219. ;; Cleaned up setq calls for efficiency. Gave more context on window overlays.
  220. ;; Assure context on ispell-command-loop.  Window lossage in look cmd fixed.
  221. ;; Due to pervasive opinion, common-lisp package syntax removed. Display
  222. ;; problem when not highlighting.
  223. ;;
  224. ;; Revision 2.19  1992/01/10  10:54:08  geoff
  225. ;; Make another attempt at fixing the "Bogus, dude" problem.  This one is
  226. ;; less elegant, but has the advantage of working.
  227. ;;
  228. ;; Revision 2.18  1992/01/07  10:04:52  geoff
  229. ;; Fix the "Bogus, Dude" problem in ispell-word.
  230. ;;
  231. ;; Revision 2.17  1991/09/12  00:01:42  geoff
  232. ;; Add some changes to make ispell-complete-word work better, though
  233. ;; still not perfectly.
  234. ;;
  235. ;; Revision 2.16  91/09/04  18:00:52  geoff
  236. ;; More updates from Sebastian, to make the multiple-dictionary support
  237. ;; more flexible.
  238. ;;
  239. ;; Revision 2.15  91/09/04  17:30:02  geoff
  240. ;; Sebastian Kremer's tib support
  241. ;;
  242. ;; Revision 2.14  91/09/04  16:19:37  geoff
  243. ;; Don't do set-window-start if the move-to-window-line moved us
  244. ;; downward, rather than upward.  This prevents getting the buffer all
  245. ;; confused.  Also, don't use the "not-modified" function to clear the
  246. ;; modification flag;  instead use set-buffer-modified-p.  This prevents
  247. ;; extra messages from flashing.
  248. ;;
  249. ;; Revision 2.13  91/09/04  14:35:41  geoff
  250. ;; Fix a spelling error in a comment.  Add code to handshake with the
  251. ;; ispell process before sending anything to it.
  252. ;;
  253. ;; Revision 2.12  91/09/03  20:14:21  geoff
  254. ;; Add Sebastian Kremer's multiple-language support.
  255. ;;
  256. ;;
  257. ;; Walt Buehring
  258. ;; Texas Instruments - Computer Science Center
  259. ;; ARPA:  Buehring%TI-CSL@CSNet-Relay
  260. ;; UUCP:  {smu, texsun, im4u, rice} ! ti-csl ! buehring
  261. ;;
  262. ;; ispell-region and associated routines added by
  263. ;; Perry Smith
  264. ;; pedz@bobkat
  265. ;; Tue Jan 13 20:18:02 CST 1987
  266. ;;
  267. ;; extensively modified by Mark Davies and Andrew Vignaux
  268. ;; {mark,andrew}@vuwcomp
  269. ;; Sun May 10 11:45:04 NZST 1987
  270. ;;
  271. ;; Ken Stevens  ARPA: k.stevens@ieee.org
  272. ;; Tue Jan  3 16:59:07 PST 1989
  273. ;; This file has overgone a major overhaul to be compatible with ispell
  274. ;; version 2.1.  Most of the functions have been totally rewritten, and
  275. ;; many user-accessible variables have been added.  The syntax table has
  276. ;; been removed since it didn't work properly anyway, and a filter is
  277. ;; used rather than a buffer.  Regular expressions are used based on
  278. ;; ispell's internal definition of characters (see ispell(4)).
  279. ;; Some new updates:
  280. ;; - Updated to version 3.0 to include terse processing.
  281. ;; - Added a variable for the look command.
  282. ;; - Fixed a bug in ispell-word when cursor is far away from the word
  283. ;;   that is to be checked.
  284. ;; - Ispell places the incorrect word or guess in the minibuffer now.
  285. ;; - fixed a bug with 'l' option when multiple windows are on the screen.
  286. ;; - lookup-words just didn't work with the process filter.  Fixed.
  287. ;; - Rewrote the process filter to make it cleaner and more robust
  288. ;;   in the event of a continued line not being completed.
  289. ;; - Made ispell-init-process more robust in handling errors.
  290. ;; - Fixed bug in continuation location after a region has been modified by
  291. ;;   correcting a misspelling.
  292. ;; Mon 17 Sept 1990
  293. ;;
  294. ;; Sebastian Kremer <sk@thp.uni-koeln.de>
  295. ;; Wed Aug  7 14:02:17 MET DST 1991
  296. ;; - Ported ispell-complete-word from Ispell 2 to Ispell 3.
  297. ;; - Added ispell-kill-ispell command.
  298. ;; - Added ispell-dictionary and ispell-dictionary-alist variables to
  299. ;;   support other than default language.  See their docstrings and
  300. ;;   command ispell-change-dictionary.
  301. ;; - (ispelled it :-)
  302. ;; - Added ispell-skip-tib variable to support the tib bibliography
  303. ;;   program.
  304.  
  305.  
  306. ;; **********************************************************************
  307. ;; The following variables should be set according to personal preference
  308. ;; and location of binaries:
  309. ;; **********************************************************************
  310.  
  311. ;;  ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1
  312.  
  313. ;;; Code:
  314.  
  315. (defgroup ispell nil
  316.   "Spell checking using ispell"
  317.   :group 'processes)
  318.  
  319.  
  320. (defcustom ispell-highlight-p t
  321.   "*Highlight spelling errors when non-nil."
  322.   :type 'boolean
  323.   :group 'ispell)
  324.  
  325. (defcustom ispell-highlight-face 'highlight
  326.   "*The face used for Ispell highlighting.  For Emacses with overlays.
  327. Possible values are `highlight', `modeline', `secondary-selection',
  328. `region', and `underline'.
  329. This variable can be set by the user to whatever face they desire.
  330. It's most convenient if the cursor color and highlight color are
  331. slightly different."
  332.   :type 'face
  333.   :group 'ispell)
  334.  
  335. (defcustom ispell-check-comments t
  336.   "*If nil, don't check spelling of comments."
  337.   :type 'boolean
  338.   :group 'ispell)
  339.  
  340. (defcustom ispell-query-replace-choices nil
  341.   "*Corrections made throughout region when non-nil.
  342. Uses `query-replace' (\\[query-replace]) for corrections."
  343.   :type 'boolean
  344.   :group 'ispell)
  345.  
  346. (defcustom ispell-skip-tib nil
  347.   "*Does not spell check `tib' bibliography references when non-nil.
  348. Skips any text between strings matching regular expressions
  349. `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
  350.  
  351. TeX users beware:  Any field starting with [. will skip until a .] -- even
  352. your whole buffer -- unless you set `ispell-skip-tib' to nil.  That includes
  353. a [.5mm] type of number...."
  354.   :type 'boolean
  355.   :group 'ispell)
  356.  
  357. (defvar ispell-tib-ref-beginning "[[<]\\."
  358.   "Regexp matching the beginning of a Tib reference.")
  359.  
  360. (defvar ispell-tib-ref-end "\\.[]>]"
  361.   "Regexp matching the end of a Tib reference.")
  362.  
  363. (defcustom ispell-keep-choices-win t
  364.   "*When not nil, the `*Choices*' window remains for spelling session.
  365. This minimizes redisplay thrashing."
  366.   :type 'boolean
  367.   :group 'ispell)
  368.  
  369. (defcustom ispell-choices-win-default-height 2
  370.   "*The default size of the `*Choices*' window, including status line.
  371. Must be greater than 1."
  372.   :type 'integer
  373.   :group 'ispell)
  374.  
  375. (defcustom ispell-program-name "ispell"
  376.   "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
  377.   :type 'string
  378.   :group 'ispell)
  379.  
  380. (defcustom ispell-alternate-dictionary
  381.   (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
  382.     ((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2")
  383.     ((file-exists-p "/usr/dict/words") "/usr/dict/words")
  384.     ((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
  385.     ((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words")
  386.     ((file-exists-p "/sys/dict") "/sys/dict")
  387.     (t "/usr/dict/words"))
  388.   "*Alternate dictionary for spelling help."
  389.   :type 'file
  390.   :group 'ispell)
  391.  
  392. (defcustom ispell-complete-word-dict ispell-alternate-dictionary
  393.   "*Dictionary used for word completion."
  394.   :type 'file
  395.   :group 'ispell)
  396.  
  397. (defvar ispell-grep-command "egrep"
  398.   "Name of the grep command for search processes.")
  399.  
  400. (defvar ispell-grep-options "-i"
  401.   "String of options to use when running the program in `ispell-grep-command'.
  402. Should probably be \"-i\" or \"-e\".
  403. Some machines (like the NeXT) don't support \"-i\"")
  404.  
  405. (defvar ispell-look-command "look"
  406.   "Name of the look command for search processes.
  407. This must be an absolute file name.")
  408.  
  409. (defcustom ispell-look-p (file-exists-p ispell-look-command)
  410.   "*Non-nil means use `look' rather than `grep'.
  411. Default is based on whether `look' seems to be available."
  412.   :type 'boolean
  413.   :group 'ispell)
  414.  
  415. (defcustom ispell-have-new-look nil
  416.   "*Non-nil means use the `-r' option (regexp) when running `look'."
  417.   :type 'boolean
  418.   :group 'ispell)
  419.  
  420. (defvar ispell-look-options (if ispell-have-new-look "-dfr" "-df")
  421.   "String of command options for `ispell-look-command'.")
  422.  
  423. (defvar ispell-use-ptys-p nil
  424.   "When non-nil, Emacs uses ptys to communicate with Ispell.
  425. When nil, Emacs uses pipes.")
  426.  
  427. (defcustom ispell-following-word nil
  428.   "*Non-nil means `ispell-word' checks the word around or after point.
  429. Otherwise `ispell-word' checks the preceding word."
  430.   :type 'boolean
  431.   :group 'ispell)
  432.  
  433. (defcustom ispell-help-in-bufferp nil
  434.   "*Non-nil means display interactive keymap help in a buffer.
  435. Otherwise use the minibuffer."
  436.   :type 'boolean
  437.   :group 'ispell)
  438.  
  439. (defcustom ispell-quietly nil
  440.   "*Non-nil means suppress messages in `ispell-word'."
  441.   :type 'boolean
  442.   :group 'ispell)
  443.  
  444. ;; upcase is not good for iso-latin!
  445. (defcustom ispell-format-word (function (lambda (str) (format "\"%s\"" str))) 
  446.   ;; was (function upcase) 
  447.   "*Formatting function for displaying word being spell checked.
  448. The function must take one string argument and return a string."
  449.   :type 'function
  450.   :group 'ispell)
  451.  
  452. ;;;###autoload
  453. (defcustom ispell-personal-dictionary nil
  454.   "*File name of your personal spelling dictionary, or nil.
  455. If nil, the default personal dictionary, \"~/.ispell_DICTNAME\" is used,
  456. where DICTNAME is the name of your default dictionary."
  457.   :type 'file
  458.   :group 'ispell)
  459.  
  460. (defcustom ispell-silently-savep nil
  461.   "*When non-nil, save the personal dictionary without confirmation."
  462.   :type 'boolean
  463.   :group 'ispell)
  464.  
  465. ;;; This variable contains the current dictionary being used if the ispell
  466. ;;; process is running.  Otherwise it contains the global default.
  467. (defvar ispell-dictionary nil
  468.   "If non-nil, a dictionary to use instead of the default one.
  469. This is passed to the ispell process using the `-d' switch and is
  470. used as key in `ispell-dictionary-alist' (which see).
  471.  
  472. You should set this variable before your first use of Emacs spell-checking
  473. commands in the Emacs session, or else use the \\[ispell-change-dictionary]
  474. command to change it.  Otherwise, this variable only takes effect in a newly
  475. started Ispell process.")
  476.  
  477. (defcustom ispell-extra-args nil
  478.   "*If non-nil, a list of extra switches to pass to the Ispell program.
  479. For example, '(\"-W\" \"3\") to cause it to accept all 1-3 character
  480. words as correct.  See also `ispell-dictionary-alist', which may be used
  481. for language-specific arguments."
  482.   :type '(repeat string)
  483.   :group 'ispell)
  484.  
  485. ;;; The preparation of the menu bar menu must be autoloaded
  486. ;;; because otherwise this file gets autoloaded every time Emacs starts
  487. ;;; so that it can set up the menus and determine keyboard equivalents.
  488.  
  489. ;;;###autoload
  490. (defvar ispell-dictionary-alist-1    ; sk  9-Aug-1991 18:28
  491.   '((nil                ; default (english.aff)
  492.      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil)
  493.     ("english"                ; make English explicitly selectable
  494.      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil)
  495.     ("british"                ; British version
  496.      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "british") nil)
  497.     ("american"                ; American version
  498.      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "american") nil)
  499.     ("deutsch"                ; deutsch.aff
  500.      "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex")
  501.     ("deutsch8"
  502.      "[a-zA-Z\304\326\334\344\366\337\374]"
  503.      "[^a-zA-Z\304\326\334\344\366\337\374]"
  504.      "[']" t ("-C" "-d" "deutsch") "~latin1" iso-8859-1)
  505.     ("nederlands"                ; nederlands.aff
  506.      "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  507.      "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  508.      "[']" t ("-C") nil iso-8859-1)
  509.     ("nederlands8"                ; dutch8.aff
  510.      "[A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  511.      "[^A-Za-z\300-\305\307\310-\317\322-\326\331-\334\340-\345\347\350-\357\361\362-\366\371-\374]"
  512.      "[']" t ("-C") nil iso-8859-1)))
  513.  
  514. ;;;###autoload
  515. (defvar ispell-dictionary-alist-2
  516.   '(("svenska"                ;7 bit swedish mode
  517.      "[A-Za-z}{|\\133\\135\\\\]" "[^A-Za-z}{|\\133\\135\\\\]"
  518.      "[']" nil ("-C") nil)
  519.     ("svenska8"                ;8 bit swedish mode
  520.      "[A-Za-z\345\344\366\305\304\366]"  "[^A-Za-z\345\344\366\305\304\366]"
  521.      "[']" nil ("-C" "-d" "svenska") "~list" ; Add `"-T" "list"' instead?
  522.      iso-8859-1)
  523.     ("norsk"                           ;8 bit norwegian mode
  524.      "[A-Za-z\351\346\370\345\311\306\330\305]"  "[^A-Za-z\351\346\370\345\311\306\330\305]"
  525.      "[']" nil ("-C" "-d" "norsk") "~list"
  526.      iso-8859-1)
  527.     ("francais7"
  528.      "[A-Za-z]" "[^A-Za-z]" "[`'^---]" t nil nil)
  529.     ("francais"                ; francais.aff
  530.      "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
  531.      "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
  532.      "[---']" t nil "~list" iso-8859-1)
  533.     ("francais-tex"            ; francais.aff
  534.      "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
  535.      "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
  536.      "[---'^`\"]" t nil "~tex" iso-8859-1)
  537.     ("italiano"                ; italiano.aff
  538.      "[A-Za-z\300\310\311\314\315\316\322\331\332\340\350\351\354\355\356\362\371\372]"
  539.      "[^A-Za-z\300\310\311\314\315\316\322\331\332\340\350\351\354\355\356\362\371\372]"
  540.      "[']" t ("-d" "italiano") "~list")
  541.     ("dansk"                ; dansk.aff
  542.      "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
  543.       "[']" nil ("-C") nil iso-8859-1)
  544.     ))
  545.  
  546.  
  547. ;;; ispell-dictionary-alist is set up from two subvariables above
  548. ;;; to avoid having very long lines in loaddefs.el.
  549. ;;;###autoload
  550. (defvar ispell-dictionary-alist
  551.   (append ispell-dictionary-alist-1 ispell-dictionary-alist-2)
  552.   "An alist of dictionaries and their associated parameters.
  553.  
  554. Each element of this list is also a list:
  555.  
  556. \(DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
  557.         ISPELL-ARGS EXTENDED-CHARACTER-MODE CODING-SYSTEM\)
  558.  
  559. DICTIONARY-NAME is a possible value of variable `ispell-dictionary', nil
  560. means the default dictionary.
  561.  
  562. CASECHARS is a regular expression of valid characters that comprise a
  563. word.
  564.  
  565. NOT-CASECHARS is the opposite regexp of CASECHARS.
  566.  
  567. OTHERCHARS are characters in the NOT-CASECHARS set but which can be used to
  568. construct words in some special way.  If OTHERCHARS characters follow and
  569. precede characters from CASECHARS, they are parsed as part of a word,
  570. otherwise they become word-breaks.  As an example in English, assume the
  571. set ['] (as a regular expression) for OTHERCHARS.  Then \"they're\" and
  572. \"Steven's\" are parsed as single words including the \"'\" character, but
  573. \"Stevens'\" does not include the quote character as part of the word.
  574. If you want OTHERCHARS to be empty, use nil.
  575. Hint: regexp syntax requires the hyphen to be declared first here.
  576.  
  577. MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
  578. Otherwise only a single OTHERCHARS character is allowed to be part of any
  579. single word.
  580.  
  581. ISPELL-ARGS is a list of additional arguments passed to the ispell
  582. subprocess.
  583.  
  584. EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
  585. have been configured in an Ispell affix file.  (For example, umlauts
  586. can be encoded as \\\"a, a\\\", \"a, ...)  Defaults are ~tex and ~nroff
  587. in English.  This has the same effect as the command-line `-T' option.
  588. The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
  589. but the dictionary can control the extended character mode.
  590. Both defaults can be overruled in a buffer-local fashion. See
  591. `ispell-parsing-keyword' for details on this.
  592.  
  593. CODING-SYSTEM is the coding system to be used for the ispell process
  594. and for decoding CASECHARS, NOT-CASECHARS and OTHERCHARS.
  595.  
  596. Note that the CASECHARS and OTHERCHARS slots of the alist should
  597. contain the same character set as casechars and otherchars in the
  598. language.aff file \(e.g., english.aff\).")
  599.  
  600. ;;;###autoload
  601. (defvar ispell-menu-map nil "Key map for ispell menu")
  602.  
  603. ;;;###autoload
  604. (defvar ispell-menu-xemacs nil "Spelling menu for XEmacs.")
  605.  
  606. ;;; Break out XEmacs menu and split into several calls to avoid having
  607. ;;; long lines in loaddefs.el.  Detect need off following constant.
  608.  
  609. ;;;###autoload
  610. (defconst ispell-menu-map-needed    ; make sure this is not XEmacs
  611.   (and (not ispell-menu-map)
  612.        (string-lessp "19" emacs-version)
  613.        ;; make sure this isn't XEmacs
  614.        (not (string-match "XEmacs" emacs-version))))
  615.  
  616.  
  617. ;;; Set up dictionary
  618. ;;;###autoload
  619. (if ispell-menu-map-needed
  620.     (let ((dicts (reverse (cons (cons "default" nil) ispell-dictionary-alist)))
  621.       name)
  622.       (setq ispell-menu-map (make-sparse-keymap "Spell"))
  623.       ;; add the dictionaries to the bottom of the list.
  624.       (while dicts
  625.     (setq name (car (car dicts))
  626.           dicts (cdr dicts))
  627.     (if (stringp name)
  628.         (define-key ispell-menu-map (vector (intern name))
  629.           (cons (concat "Select " (capitalize name))
  630.             (list 'lambda () '(interactive)
  631.               (list 'ispell-change-dictionary name))))))))
  632.  
  633. ;;; define commands in menu in opposite order you want them to appear.
  634. ;;;###autoload
  635. (if ispell-menu-map-needed
  636.     (progn
  637.       (define-key ispell-menu-map [ispell-change-dictionary]
  638.     '("Change Dictionary" . ispell-change-dictionary))
  639.       (define-key ispell-menu-map [ispell-kill-ispell]
  640.     '("Kill Process" . ispell-kill-ispell))
  641.       (define-key ispell-menu-map [ispell-pdict-save]
  642.     '("Save Dictionary" . (lambda () (interactive) (ispell-pdict-save t t))))
  643.       (define-key ispell-menu-map [ispell-complete-word]
  644.     '("Complete Word" . ispell-complete-word))
  645.       (define-key ispell-menu-map [ispell-complete-word-interior-frag]
  646.     '("Complete Word Frag" . ispell-complete-word-interior-frag))))
  647.  
  648. ;;;###autoload
  649. (if ispell-menu-map-needed
  650.     (progn
  651.       (define-key ispell-menu-map [ispell-continue]
  652.     '("Continue Check" . ispell-continue))
  653.       (define-key ispell-menu-map [ispell-word]
  654.     '("Check Word" . ispell-word))
  655.       (define-key ispell-menu-map [ispell-region]
  656.     '("Check Region" . ispell-region))
  657.       (define-key ispell-menu-map [ispell-buffer]
  658.     '("Check Buffer" . ispell-buffer))))
  659.  
  660. ;;;###autoload
  661. (if ispell-menu-map-needed
  662.     (progn
  663.       (define-key ispell-menu-map [ispell-message]
  664.     '("Check Message" . ispell-message))
  665.       (define-key ispell-menu-map [ispell-help]
  666.     ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
  667.     '("Help" . (lambda () (interactive) (describe-function 'ispell-help))))
  668.       (put 'ispell-region 'menu-enable 'mark-active)
  669.       (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
  670.  
  671. ;;; XEmacs version 19
  672. (if (and (string-lessp "19" emacs-version)
  673.      (string-match "Lucid" emacs-version)
  674.      (not (and (boundp 'infodock-version) infodock-version))
  675.      (featurep 'menubar)
  676.      (or current-menubar default-menubar))
  677.     (let ((dicts (cons (cons "default" nil) ispell-dictionary-alist))
  678.       (current-menubar (or current-menubar default-menubar))
  679.       (menu
  680.        '(["Help"        (describe-function 'ispell-help) t]
  681.          ;;["Help"        (popup-menu ispell-help-list)    t]
  682.          ["Check Message"    ispell-message            t]
  683.          ["Check Buffer"    ispell-buffer            t]
  684.          ["Check Word"    ispell-word            t]
  685.          ["Check Region"    ispell-region  (or (not zmacs-regions) (mark))]
  686.          ["Continue Check"    ispell-continue            t]
  687.          ["Complete Word Frag"ispell-complete-word-interior-frag t]
  688.          ["Complete Word"    ispell-complete-word        t]
  689.          ["Kill Process"    ispell-kill-ispell        t]
  690.          "-"
  691.          ["Save Dictionary"    (ispell-pdict-save t t)        t]
  692.          ["Change Dictionary" ispell-change-dictionary    t]))
  693.       name)
  694.       (while dicts
  695.     (setq name (car (car dicts))
  696.           dicts (cdr dicts))
  697.     (if (stringp name)
  698.         (setq menu (append menu
  699.                    (list
  700.                 (vector (concat "Select " (capitalize name))
  701.                     (list 'ispell-change-dictionary name)
  702.                     t))))))
  703.       (setq ispell-menu-xemacs menu)
  704.       (if current-menubar
  705.       (progn
  706.         (delete-menu-item '("Edit" "Spell")) ; in case already defined
  707.         (add-menu '("Edit") "Spell" ispell-menu-xemacs)))))
  708.  
  709.  
  710. ;;; **********************************************************************
  711. ;;; The following are used by ispell, and should not be changed.
  712. ;;; **********************************************************************
  713.  
  714.  
  715. ;;; The version must be 3.1 or greater for this version of ispell.el
  716. ;;; There is an incompatibility between version 3.1.12 and lower versions.
  717. (defconst ispell-required-version '("3.1." 12)
  718.   "Ispell versions with which this version of ispell.el is known to work.")
  719. (defvar ispell-offset 1
  720.   "Offset that maps protocol differences between ispell 3.1 versions.")
  721.  
  722. (defun ispell-decode-string (str)
  723.   (let (coding-system)
  724.     (if (setq coding-system (ispell-get-coding-system))
  725.     (decode-coding-string str coding-system)
  726.       str)))
  727.  
  728. (defun ispell-get-casechars ()
  729.   (ispell-decode-string
  730.    (nth 1 (assoc ispell-dictionary ispell-dictionary-alist))))
  731. (defun ispell-get-not-casechars ()
  732.   (ispell-decode-string
  733.    (nth 2 (assoc ispell-dictionary ispell-dictionary-alist))))
  734. (defun ispell-get-otherchars ()
  735.   (ispell-decode-string
  736.    (nth 3 (assoc ispell-dictionary ispell-dictionary-alist))))
  737. (defun ispell-get-many-otherchars-p ()
  738.   (nth 4 (assoc ispell-dictionary ispell-dictionary-alist)))
  739. (defun ispell-get-ispell-args ()
  740.   (nth 5 (assoc ispell-dictionary ispell-dictionary-alist)))
  741. (defun ispell-get-extended-character-mode ()
  742.   (nth 6 (assoc ispell-dictionary ispell-dictionary-alist)))
  743. (defun ispell-get-coding-system ()
  744.   (nth 7 (assoc ispell-dictionary ispell-dictionary-alist)))
  745.  
  746. (defvar ispell-process nil
  747.   "The process object for Ispell.")
  748.  
  749. (defvar ispell-pdict-modified-p nil
  750.   "Non-nil means personal dictionary has modifications to be saved.")
  751.  
  752. ;;; If you want to save the dictionary when quitting, must do so explicitly.
  753. ;;; When non-nil, the spell session is terminated.
  754. ;;; When numeric, contains cursor location in buffer, and cursor remains there.
  755. (defvar ispell-quit nil)
  756.  
  757. (defvar ispell-filter nil
  758.   "Output filter from piped calls to Ispell.")
  759.  
  760. (defvar ispell-filter-continue nil
  761.   "Control variable for Ispell filter function.")
  762.  
  763. (defvar ispell-process-directory nil
  764.   "The directory where `ispell-process' was started.")
  765.  
  766. (defvar ispell-query-replace-marker (make-marker)
  767.   "Marker for `query-replace' processing.")
  768.  
  769. (defvar ispell-checking-message nil
  770.   "Non-nil when we're checking a mail message")
  771.  
  772. (defconst ispell-choices-buffer "*Choices*")
  773.  
  774. (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
  775.  
  776. ;;; *** Buffer Local Definitions ***
  777.  
  778. ;;; This is the local dictionary to use.  When nil the default dictionary will
  779. ;;; be used.  Do not redefine default value or it will override the global!
  780. (defvar ispell-local-dictionary nil
  781.   "If non-nil, a dictionary to use for Ispell commands in this buffer.
  782. The value must be a string dictionary name in `ispell-dictionary-alist'.
  783. This variable becomes buffer-local when set in any fashion.
  784.  
  785. Setting ispell-local-dictionary to a value has the same effect as
  786. calling \\[ispell-change-dictionary] with that value.  This variable
  787. is automatically set when defined in the file with either
  788. `ispell-dictionary-keyword' or the Local Variable syntax.")
  789.  
  790. (make-variable-buffer-local 'ispell-local-dictionary)
  791.  
  792. ;; Use default directory, unless locally set.
  793. (set-default 'ispell-local-dictionary nil)
  794.  
  795. (defconst ispell-words-keyword "LocalWords: "                      
  796.   "The keyword for local oddly-spelled words to accept.
  797. The keyword will be followed by any number of local word spellings.
  798. There can be multiple of these keywords in the file.")
  799.  
  800. (defconst ispell-dictionary-keyword "Local IspellDict: "
  801.   "The keyword for local dictionary definitions.
  802. There should be only one dictionary keyword definition per file, and it
  803. should be followed by a correct dictionary name in `ispell-dictionary-alist'.")
  804.  
  805. (defconst ispell-parsing-keyword "Local IspellParsing: "
  806.   "The keyword for overriding default Ispell parsing.
  807. Determined by the buffer's major mode and extended-character mode as well as
  808. the default dictionary.
  809.  
  810. The above keyword string should be followed by `latex-mode' or
  811. `nroff-mode' to put the current buffer into the desired parsing mode.
  812.  
  813. Extended character mode can be changed for this buffer by placing
  814. a `~' followed by an extended-character mode -- such as `~.tex'.")
  815.  
  816. (defvar ispell-skip-sgml nil
  817.   "Skips spell checking of SGML tags and entity references when non-nil.
  818. This variable is set when major-mode is sgml-mode or html-mode.")
  819.  
  820. ;;;###autoload
  821. (defvar ispell-local-pdict ispell-personal-dictionary
  822.   "A buffer local variable containing the current personal dictionary.
  823. If non-nil, the value must be a string, which is a file name.
  824.  
  825. If you specify a personal dictionary for the current buffer which is
  826. different from the current personal dictionary, the effect is similar
  827. to calling \\[ispell-change-dictionary].  This variable is automatically
  828. set when defined in the file with either `ispell-pdict-keyword' or the
  829. local variable syntax.")
  830.  
  831. (make-variable-buffer-local 'ispell-local-pdict)
  832.  
  833. (defconst ispell-pdict-keyword "Local IspellPersDict: "
  834.   "The keyword for defining buffer local dictionaries.")
  835.  
  836. (defvar ispell-buffer-local-name nil
  837.   "Contains the buffer name if local word definitions were used.
  838. Ispell is then restarted because the local words could conflict.")
  839.  
  840. (defvar ispell-parser 'use-mode-name
  841.    "*Indicates whether ispell should parse the current buffer as TeX Code.
  842. Special value `use-mode-name' tries to guess using the name of major-mode.
  843. Default parser is 'nroff.
  844. Currently the only other valid parser is 'tex.
  845.  
  846. You can set this variable in hooks in your init file -- eg:
  847.  
  848. (add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))")
  849.  
  850. (defvar ispell-region-end (make-marker)
  851.   "Marker that allows spelling continuations.")
  852.  
  853. (defvar ispell-check-only nil
  854.   "If non-nil, `ispell-word' does not try to correct the word.")
  855.  
  856.  
  857. ;;; **********************************************************************
  858. ;;; **********************************************************************
  859.  
  860.  
  861. (and (string-lessp "19" emacs-version)
  862.      (not (boundp 'epoch::version))
  863.      (defalias 'ispell 'ispell-buffer))
  864.  
  865.  
  866. ;; XEmacs: \M-$ for whatever reason, drives `make autoloads' bonkers
  867.  
  868. ;;;###autoload
  869. (define-key global-map [(meta ?\$)] 'ispell-word)
  870.  
  871. ;;;###autoload
  872. (defun ispell-word (&optional following quietly continue)
  873.   "Check spelling of word under or before the cursor.
  874. If the word is not found in dictionary, display possible corrections
  875. in a window allowing you to choose one.
  876.  
  877. With a prefix argument (or if CONTINUE is non-nil),
  878. resume interrupted spell-checking of a buffer or region.
  879.  
  880. If optional argument FOLLOWING is non-nil or if `ispell-following-word'
  881. is non-nil when called interactively, then the following word
  882. \(rather than preceding\) is checked when the cursor is not over a word.
  883. When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
  884. when called interactively, non-corrective messages are suppressed.
  885.  
  886. Word syntax described by `ispell-dictionary-alist' (which see).
  887.  
  888. This will check or reload the dictionary.  Use \\[ispell-change-dictionary]
  889. or \\[ispell-region] to update the Ispell process."
  890.   (interactive (list nil nil current-prefix-arg))
  891.   (if continue
  892.       (ispell-continue)
  893.     (if (interactive-p)
  894.     (setq following ispell-following-word
  895.           quietly ispell-quietly))
  896.     (ispell-accept-buffer-local-defs)    ; use the correct dictionary
  897.     (let ((cursor-location (point))    ; retain cursor location
  898.       (word (ispell-get-word following))
  899.       start end poss replace)
  900.       ;; destructure return word info list.
  901.       (setq start (car (cdr word))
  902.         end (car (cdr (cdr word)))
  903.         word (car word))
  904.  
  905.       ;; now check spelling of word.
  906.       (or quietly
  907.       (message "Checking spelling of %s..."
  908.            (funcall ispell-format-word word)))
  909.       (process-send-string ispell-process "%\n") ;put in verbose mode
  910.       (process-send-string ispell-process (concat "^" word "\n"))
  911.       ;; wait until ispell has processed word
  912.       (while (progn
  913.            (accept-process-output ispell-process)
  914.            (not (string= "" (car ispell-filter)))))
  915.       ;;(process-send-string ispell-process "!\n") ;back to terse mode.
  916.       (setq ispell-filter (cdr ispell-filter))
  917.       (if (listp ispell-filter)
  918.       (setq poss (ispell-parse-output (car ispell-filter))))
  919.       (cond ((eq poss t)
  920.          (or quietly
  921.          (message "%s is correct" (funcall ispell-format-word word))))
  922.         ((stringp poss)
  923.          (or quietly
  924.          (message "%s is correct because of root %s"
  925.               (funcall ispell-format-word word)
  926.               (funcall ispell-format-word poss))))
  927.         ((null poss) (message "Error in ispell process"))
  928.         (ispell-check-only        ; called from ispell minor mode.
  929.          (beep))
  930.         (t                ; prompt for correct word.
  931.          (save-window-excursion
  932.            (setq replace (ispell-command-loop
  933.                   (car (cdr (cdr poss)))
  934.                   (car (cdr (cdr (cdr poss))))
  935.                   (car poss) start end)))
  936.          (cond ((equal 0 replace)
  937.             (ispell-add-per-file-word-list (car poss)))
  938.            (replace
  939.             (setq word (if (atom replace) replace (car replace))
  940.               cursor-location (+ (- (length word) (- end start))
  941.                          cursor-location))
  942.             (if (not (equal word (car poss)))
  943.             (progn
  944.               (delete-region start end)
  945.               (insert word)))
  946.             (if (not (atom replace)) ; recheck spelling of replacement
  947.             (progn
  948.               (goto-char cursor-location)
  949.               (ispell-word following quietly)))))
  950.          (if (get-buffer ispell-choices-buffer)
  951.          (kill-buffer ispell-choices-buffer))))
  952.       (goto-char cursor-location)    ; return to original location
  953.       (ispell-pdict-save ispell-silently-savep)
  954.       (if ispell-quit (setq ispell-quit nil)))))
  955.  
  956.  
  957. (defun ispell-get-word (following &optional extra-otherchars)
  958.   "Return the word for spell-checking according to ispell syntax.
  959. If optional argument FOLLOWING is non-nil or if `ispell-following-word'
  960. is non-nil when called interactively, then the following word
  961. \(rather than preceding\) is checked when the cursor is not over a word.
  962. Optional second argument contains otherchars that can be included in word
  963. many times.
  964.  
  965. Word syntax described by `ispell-dictionary-alist' (which see)."
  966.   (let* ((ispell-casechars (ispell-get-casechars))
  967.      (ispell-not-casechars (ispell-get-not-casechars))
  968.      (ispell-otherchars (ispell-get-otherchars))
  969.      (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
  970.      (word-regexp (concat ispell-casechars
  971.                   "+\\("
  972.                   (unless (string-equal ispell-otherchars "")
  973.                 (concat ispell-otherchars "?"))
  974.                   (unless (or (null extra-otherchars)
  975.                       (string-equal extra-otherchars ""))
  976.                 (concat extra-otherchars "?"))
  977.                   ispell-casechars
  978.                   "+\\)"
  979.                   (if (or ispell-many-otherchars-p
  980.                       extra-otherchars)
  981.                   "*" "?")))
  982.      did-it-once
  983.      start end word)
  984.     ;; find the word
  985.     (if (not (looking-at ispell-casechars))
  986.     (if following
  987.         (re-search-forward ispell-casechars (point-max) t)
  988.       (re-search-backward ispell-casechars (point-min) t)))
  989.     ;; move to front of word
  990.     (re-search-backward ispell-not-casechars (point-min) 'start)
  991.     (while (and (or (looking-at ispell-otherchars)
  992.             (and extra-otherchars (looking-at extra-otherchars)))
  993.         (not (bobp))
  994.         (or (not did-it-once)
  995.             ispell-many-otherchars-p))
  996.       (if (and extra-otherchars (looking-at extra-otherchars))
  997.       (progn
  998.         (backward-char 1)
  999.         (if (looking-at ispell-casechars)
  1000.         (re-search-backward ispell-not-casechars (point-min) 'move)))
  1001.     (setq did-it-once t)
  1002.     (backward-char 1)
  1003.     (if (looking-at ispell-casechars)
  1004.         (re-search-backward ispell-not-casechars (point-min) 'move)
  1005.       (backward-char -1))))
  1006.     ;; Now mark the word and save to string.
  1007.     (or (re-search-forward word-regexp (point-max) t)
  1008.     (error "No word found to check!"))
  1009.     (setq start (match-beginning 0)
  1010.       end (point)
  1011.       word (buffer-substring start end))
  1012.     (list word start end)))
  1013.  
  1014.  
  1015. ;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
  1016. ;;; tracks changes in the dictionary.  The global may either be
  1017. ;;; a value or a list, whose value is the state of whether the
  1018. ;;; dictionary needs to be saved.
  1019.  
  1020. (defun ispell-pdict-save (&optional no-query force-save)
  1021.   "Check to see if the personal dictionary has been modified.
  1022. If so, ask if it needs to be saved."
  1023.   (interactive (list ispell-silently-savep t))
  1024.   (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
  1025.       (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
  1026.   (if (or ispell-pdict-modified-p force-save)
  1027.       (if (or no-query (y-or-n-p "Personal dictionary modified.  Save? "))
  1028.       (progn
  1029.         (process-send-string ispell-process "#\n")
  1030.         (message "Personal dictionary saved."))))
  1031.   ;; unassert variable, even if not saved to avoid questioning.
  1032.   (setq ispell-pdict-modified-p nil))
  1033.  
  1034.  
  1035. (defun ispell-command-loop (miss guess word start end)
  1036.   "Display possible corrections from list MISS.
  1037. GUESS lists possibly valid affix construction of WORD.
  1038. Returns nil to keep word.
  1039. Returns 0 to insert locally into buffer-local dictionary.
  1040. Returns string for new chosen word.
  1041. Returns list for new replacement word (will be rechecked).
  1042. Highlights the word, which is assumed to run from START to END.
  1043. Global `ispell-pdict-modified-p' becomes a list where the only value
  1044. indicates whether the dictionary has been modified when option `a' or `i' is
  1045. used."
  1046.   (let ((textbuf (current-buffer))
  1047.     (count ?0)
  1048.     (line 2)
  1049.     (max-lines (- (window-height) 4)) ; assure 4 context lines.
  1050.     (choices miss)
  1051.     (window-min-height (min window-min-height
  1052.                 ispell-choices-win-default-height))
  1053.     (command-characters '( ?  ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
  1054.     (skipped 0)
  1055.     char num result textwin highlighted)
  1056.  
  1057.     ;; setup the *Choices* buffer with valid data.
  1058.     (save-excursion
  1059.       (set-buffer (get-buffer-create ispell-choices-buffer))
  1060.       (setq mode-line-format (concat "--  %b  --  word: " word))
  1061.       ;; XEmacs: turn off the modeline
  1062.       (and (fboundp 'set-specifier)
  1063.        (set-specifier has-modeline-p (cons (current-buffer) nil)))
  1064.       (erase-buffer)
  1065.       (if guess
  1066.       (progn
  1067.         (insert "Affix rules generate and capitalize "
  1068.             "this word as shown below:\n\t")
  1069.         (while guess
  1070.           (if (> (+ 4 (current-column) (length (car guess)))
  1071.              (window-width))
  1072.           (progn
  1073.             (insert "\n\t")
  1074.             (setq line (1+ line))))
  1075.           (insert (car guess) "    ")
  1076.           (setq guess (cdr guess)))
  1077.         (insert "\nUse option `i' if this is a correct composition"
  1078.             " from the derivative root.\n")
  1079.         (setq line (+ line (if choices 3 2)))))
  1080.       (while (and choices
  1081.           (< (if (> (+ 7 (current-column) (length (car choices))
  1082.                    (if (> count ?~) 3 0))
  1083.                 (window-width))
  1084.              (progn
  1085.                (insert "\n")
  1086.                (setq line (1+ line)))
  1087.                line)
  1088.              max-lines))
  1089.     ;; not so good if there are over 20 or 30 options, but then, if
  1090.     ;; there are that many you don't want to scan them all anyway...
  1091.     (when (integerp count)
  1092.       (setq count (int-char count)))
  1093.     (while (memq count command-characters) ; skip command characters.
  1094.       (setq count (int-char (1+ count))
  1095.         skipped (1+ skipped)))
  1096.     (insert "(" count ") " (car choices) "  ")
  1097.     (setq choices (cdr choices)
  1098.           count (1+ count)))
  1099.       (setq count (int-char (- count ?0 skipped))))
  1100.  
  1101.     ;; Assure word is visible
  1102.     (if (not (pos-visible-in-window-p end))
  1103.     (sit-for 0))
  1104.     ;; Display choices for misspelled word.
  1105.     (let ((choices-window (get-buffer-window ispell-choices-buffer)))
  1106.       (if choices-window
  1107.       (if (= line (window-height choices-window))
  1108.           (select-window choices-window)
  1109.         ;; *Choices* window changed size.  Adjust the choices window
  1110.         ;; without scrolling the spelled window when possible
  1111.         (let ((window-line (- line (window-height choices-window)))
  1112.           (visible (progn (forward-line -1) (point))))
  1113.           (if (< line ispell-choices-win-default-height)
  1114.           (setq window-line (+ window-line
  1115.                        (- ispell-choices-win-default-height
  1116.                       line))))
  1117.           (move-to-window-line 0)
  1118.           (forward-line window-line)
  1119.           (set-window-start (selected-window)
  1120.                 (if (> (point) visible) visible (point)))
  1121.           (goto-char end)
  1122.           (select-window (previous-window)) ; *Choices* window
  1123.           (enlarge-window window-line)))
  1124.     ;; Overlay *Choices* window when it isn't showing
  1125.     (ispell-overlay-window (max line ispell-choices-win-default-height)))
  1126.       (switch-to-buffer ispell-choices-buffer)
  1127.       (goto-char (point-min)))
  1128.  
  1129.     (select-window (setq textwin (next-window)))
  1130.  
  1131.     ;; highlight word, protecting current buffer status
  1132.     (unwind-protect
  1133.     (progn
  1134.       (if ispell-highlight-p
  1135.           (ispell-highlight-spelling-error start end t))
  1136.       ;; Loop until a valid choice is made.
  1137.       (while
  1138.           (eq
  1139.            t
  1140.            (setq
  1141.         result
  1142.         (progn
  1143.           (undo-boundary)
  1144.           (display-message 'prompt
  1145.               (concat "C-h or ? for more options; SPC to leave "
  1146.                   "unchanged, Character to replace word"))
  1147.           (let ((inhibit-quit t))
  1148.             (setq char (if (fboundp 'read-char-exclusive)
  1149.                    (read-char-exclusive)
  1150.                  (read-char))
  1151.               skipped 0)
  1152.             (if (or quit-flag (eq char ?\C-g)) ; C-g is like typing X
  1153.             (setq char ?X
  1154.                   quit-flag nil)))
  1155.           ;; Adjust num to array offset skipping command characters.
  1156.           (let ((com-chars command-characters))
  1157.             (while com-chars
  1158.               (if (and (> (car com-chars) ?0) (< (car com-chars) char))
  1159.               (setq skipped (1+ skipped)))
  1160.               (setq com-chars (cdr com-chars)))
  1161.             (setq num (- char ?0 skipped)))
  1162.  
  1163.           (cond
  1164.            ((eq char ? ) nil)    ; accept word this time only
  1165.            ((eq char ?i)    ; accept and insert word into pers dict
  1166.             (process-send-string ispell-process (concat "*" word "\n"))
  1167.             (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
  1168.             nil)
  1169.            ((or (eq char ?a) (eq char ?A)) ; accept word without insert
  1170.             (process-send-string ispell-process (concat "@" word "\n"))
  1171.             (if (null ispell-pdict-modified-p)
  1172.             (setq ispell-pdict-modified-p
  1173.                   (list ispell-pdict-modified-p)))
  1174.             (if (eq char ?A) 0)) ; return 0 for ispell-add buffer-local
  1175.            ((or (eq char ?r) (eq char ?R)) ; type in replacement
  1176.             (if (or (eq char ?R) ispell-query-replace-choices)
  1177.             (list (read-string "Query-replacement for: " word) t)
  1178.               (cons (read-string "Replacement for: " word) nil)))
  1179.            ((or (eq char ??)
  1180.             ;; XEmacs change: help-char may not be an int.
  1181.             (eq char (event-to-character
  1182.                   (character-to-event help-char)))
  1183.             (eq char ?\C-h))
  1184.             (ispell-help)
  1185.             t)
  1186.            ;; Quit and move point back.
  1187.            ((eq char ?x)
  1188.             (ispell-pdict-save ispell-silently-savep)
  1189.             (message "Exited spell-checking")
  1190.             (setq ispell-quit t)
  1191.             nil)
  1192.            ;; Quit and preserve point.
  1193.            ((eq char ?X)
  1194.             (ispell-pdict-save ispell-silently-savep)
  1195.             (message "%s"
  1196.              (substitute-command-keys
  1197.               (concat "Spell-checking suspended;"
  1198.                   " use C-u \\[ispell-word] to resume")))
  1199.             (setq ispell-quit (max (point-min)
  1200.                        (- (point) (length word))))
  1201.             nil)
  1202.            ((eq char ?q)
  1203.             (if (y-or-n-p "Really kill Ispell process? ")
  1204.             (progn
  1205.               (ispell-kill-ispell t) ; terminate process.
  1206.               (setq ispell-quit (or (not ispell-checking-message)
  1207.                         (point))
  1208.                 ispell-pdict-modified-p nil))
  1209.               t))        ; continue if they don't quit.
  1210.            ((eq char ?l)
  1211.             (let ((new-word (read-string
  1212.                      "Lookup string (`*' is wildcard): "
  1213.                      word))
  1214.               (new-line 2))
  1215.               (if new-word
  1216.               (progn
  1217.                 (save-excursion
  1218.                   (set-buffer (get-buffer-create
  1219.                        ispell-choices-buffer))
  1220.                   (erase-buffer)
  1221.                   (setq count ?0
  1222.                     skipped 0
  1223.                     mode-line-format (concat
  1224.                               "--  %b  --  word: "
  1225.                               new-word)
  1226.                     miss (lookup-words new-word)
  1227.                     choices miss)
  1228.                   (while (and choices ; adjust choices window.
  1229.                       (< (if (> (+ 7 (current-column)
  1230.                                (length (car choices))
  1231.                                (if (> count ?~) 3 0))
  1232.                             (window-width))
  1233.                          (progn
  1234.                            (insert "\n")
  1235.                            (setq new-line
  1236.                              (1+ new-line)))
  1237.                            new-line)
  1238.                          max-lines))
  1239.                 (while (memq count command-characters)
  1240.                   (setq count (int-char (1+ count))
  1241.                     skipped (1+ skipped)))
  1242.                 (insert "(" count ") " (car choices) "  ")
  1243.                 (setq choices (cdr choices)
  1244.                       count (1+ count)))
  1245.                   (setq count (- count ?0 skipped)))
  1246.                 (select-window (previous-window))
  1247.                 (if (and (/= new-line line)
  1248.                      (> (max line new-line)
  1249.                     ispell-choices-win-default-height))
  1250.                 (let* ((minh ispell-choices-win-default-height)
  1251.                        (gr-bl (if (< line minh) ; blanks
  1252.                           (- minh line)
  1253.                         0))
  1254.                        (shr-bl (if (< new-line minh) ; blanks
  1255.                            (- minh new-line)
  1256.                          0)))
  1257.                   (if (> new-line line)
  1258.                       (enlarge-window (- new-line line gr-bl))
  1259.                     (shrink-window (- line new-line shr-bl)))
  1260.                   (setq line new-line)))
  1261.                 (select-window (next-window)))))
  1262.             t)            ; reselect from new choices
  1263.            ((eq char ?u)
  1264.             (process-send-string ispell-process
  1265.                      (concat "*" (downcase word) "\n"))
  1266.             (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
  1267.             nil)
  1268.            ((eq char ?m)    ; type in what to insert
  1269.             (process-send-string
  1270.              ispell-process (concat "*" (read-string "Insert: " word)
  1271.                         "\n"))
  1272.             (setq ispell-pdict-modified-p '(t))
  1273.             (cons word nil))
  1274.            ((and (>= num 0) (< num count))
  1275.             (if ispell-query-replace-choices ; Query replace flag
  1276.             (list (nth num miss) 'query-replace)
  1277.               (nth num miss)))
  1278.            ((eq char ?\C-l)
  1279.             (redraw-display) t)
  1280.            ((eq char ?\C-r)
  1281.             (save-window-excursion (recursive-edit)) t)
  1282.            ((eq char ?\C-z)
  1283.             (funcall (key-binding "\C-z"))
  1284.             t)
  1285.            (t (ding) t))))))
  1286.       result)
  1287.       ;; protected
  1288.       (if ispell-highlight-p        ; unhighlight
  1289.       (save-window-excursion
  1290.         (select-window textwin)
  1291.         (ispell-highlight-spelling-error start end))))))
  1292.  
  1293.  
  1294. ;;;###autoload
  1295. (defun ispell-help ()
  1296.   "Display a list of the options available when a misspelling is encountered.
  1297.  
  1298. Selections are:
  1299.  
  1300. DIGIT: Replace the word with a digit offered in the *Choices* buffer.
  1301. SPC:   Accept word this time.
  1302. `i':   Accept word and insert into private dictionary.
  1303. `a':   Accept word for this session.
  1304. `A':   Accept word and place in `buffer-local dictionary'.
  1305. `r':   Replace word with typed-in value.  Rechecked.
  1306. `R':   Replace word with typed-in value. Query-replaced in buffer. Rechecked.
  1307. `?':   Show these commands.
  1308. `x':   Exit spelling buffer.  Move cursor to original point.
  1309. `X':   Exit spelling buffer.  Leaves cursor at the current point, and permits
  1310.         the aborted check to be completed later.
  1311. `q':   Quit spelling session (Kills ispell process).
  1312. `l':   Look up typed-in replacement in alternate dictionary.  Wildcards okay.
  1313. `u':   Like `i', but the word is lower-cased first.
  1314. `m':   Like `i', but allows one to include dictionary completion information.
  1315. `C-l':  redraws screen
  1316. `C-r':  recursive edit
  1317. `C-z':  suspend emacs or iconify frame"
  1318.  
  1319.   (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
  1320.             "[i]nsert into private dictionary"))
  1321.     (help-2 (concat "[l]ook a word up in alternate dictionary;  "
  1322.             "e[x/X]it;  [q]uit session"))
  1323.     (help-3 (concat "[u]ncapitalized insert into dictionary.  "
  1324.             "Type 'C-h d ispell-help' for more help")))
  1325.     (save-window-excursion
  1326.       (if ispell-help-in-bufferp
  1327.       (progn
  1328.         (ispell-overlay-window 4)
  1329.         (switch-to-buffer (get-buffer-create "*Ispell Help*"))
  1330.         (insert (concat help-1 "\n" help-2 "\n" help-3))
  1331.         (sit-for 5)
  1332.         (kill-buffer "*Ispell Help*"))
  1333.     (select-window (minibuffer-window))
  1334.     ;;(enlarge-window 2)
  1335.     (erase-buffer)
  1336.     (cond ((and (< emacs-minor-version 12)
  1337.             (string-match "Lucid" emacs-version))
  1338.            (message help-3)
  1339.            (enlarge-window 1)
  1340.            (message help-2)
  1341.            (enlarge-window 1)
  1342.            (message help-1)
  1343.            (goto-char (point-min)))
  1344.           (t
  1345.            (if (string-lessp "19" emacs-version)
  1346.            (message nil))
  1347.            (enlarge-window 2)
  1348.            ;; Make sure we display the minibuffer
  1349.            ;; in this window, not some other.
  1350.            (if (fboundp 'set-minibuffer-window)
  1351.            (set-minibuffer-window (selected-window)))
  1352.            (insert (concat help-1 "\n" help-2 "\n" help-3))))
  1353.     (sit-for 5)
  1354.     (erase-buffer)))))
  1355.  
  1356.  
  1357. (defun lookup-words (word &optional lookup-dict)
  1358.   "Look up word in word-list dictionary.
  1359. A `*' serves as a wild card.  If no wild cards, `look' is used if it exists.
  1360. Otherwise the variable `ispell-grep-command' contains the command used to
  1361. search for the words (usually egrep).
  1362.  
  1363. Optional second argument contains the dictionary to use; the default is
  1364. `ispell-alternate-dictionary'."
  1365.   ;; We don't use the filter for this function, rather the result is written
  1366.   ;; into a buffer.  Hence there is no need to save the filter values.
  1367.   (if (null lookup-dict)
  1368.       (setq lookup-dict ispell-alternate-dictionary))
  1369.  
  1370.   (let* ((process-connection-type ispell-use-ptys-p)
  1371.      (wild-p (string-match "\\*" word))
  1372.      (look-p (and ispell-look-p    ; Only use look for an exact match.
  1373.               (or ispell-have-new-look (not wild-p))))
  1374.      (ispell-grep-buffer (get-buffer-create "*Ispell-Temp*")) ; result buf
  1375.      (prog (if look-p ispell-look-command ispell-grep-command))
  1376.      (args (if look-p ispell-look-options ispell-grep-options))
  1377.      status results loc)
  1378.     (unwind-protect
  1379.     (save-window-excursion
  1380.       (message "Starting \"%s\" process..." (file-name-nondirectory prog))
  1381.       (set-buffer ispell-grep-buffer)
  1382.       (if look-p
  1383.           nil
  1384.         ;; convert * to .*
  1385.         (insert "^" word "$")
  1386.         (while (search-backward "*" nil t) (insert "."))
  1387.         (setq word (buffer-string))
  1388.         (erase-buffer))
  1389.       (setq status (call-process prog nil t nil args word lookup-dict))
  1390.       ;; grep returns status 1 and no output when word not found, which
  1391.       ;; is a perfectly normal thing.
  1392.       (if (stringp status)
  1393.           (setq results (cons (format "error: %s exited with signal %s"
  1394.                       (file-name-nondirectory prog) status)
  1395.                   results))
  1396.         ;; else collect words into `results' in FIFO order
  1397.         (goto-char (point-max))
  1398.         ;; assure we've ended with \n
  1399.         (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
  1400.         (while (not (bobp))
  1401.           (setq loc (point))
  1402.           (forward-line -1)
  1403.           (setq results (cons (buffer-substring (point) (1- loc))
  1404.                   results)))))
  1405.       ;; protected
  1406.       (kill-buffer ispell-grep-buffer)
  1407.       (if (and results (string-match ".+: " (car results)))
  1408.       (error "%s error: %s" ispell-grep-command (car results))))
  1409.     results))
  1410.  
  1411.  
  1412. ;;; "ispell-filter" is a list of output lines from the generating function.
  1413. ;;;   Each full line (ending with \n) is a separate item on the list.
  1414. ;;; "output" can contain multiple lines, part of a line, or both.
  1415. ;;; "start" and "end" are used to keep bounds on lines when "output" contains
  1416. ;;;   multiple lines.
  1417. ;;; "ispell-filter-continue" is true when we have received only part of a
  1418. ;;;   line as output from a generating function ("output" did not end with \n)
  1419. ;;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
  1420. ;;;   This is the case when a process dies or fails. The default behavior
  1421. ;;;   in this case treats the next input received as fresh input.
  1422.  
  1423. (defun ispell-filter (process output)
  1424.   "Output filter function for ispell, grep, and look."
  1425.   (let ((start 0)
  1426.     (continue t)
  1427.     end)
  1428.     (while continue
  1429.       (setq end (string-match "\n" output start)) ; get text up to the newline.
  1430.       ;; If we get out of sync and ispell-filter-continue is asserted when we
  1431.       ;; are not continuing, treat the next item as a separate list.  When
  1432.       ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
  1433.       ;; list!
  1434.  
  1435.       ;; Continue with same line (item)?
  1436.       (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
  1437.       ;; Yes.  Add it to the prev item
  1438.       (setcar ispell-filter
  1439.           (concat (car ispell-filter) (substring output start end)))
  1440.     ;; No. This is a new line and item.
  1441.     (setq ispell-filter
  1442.           (cons (substring output start end) ispell-filter)))
  1443.       (if (null end)
  1444.       ;; We've completed reading the output, but didn't finish the line.
  1445.       (setq ispell-filter-continue t continue nil)
  1446.     ;; skip over newline, this line complete.
  1447.     (setq ispell-filter-continue nil end (1+ end))
  1448.     (if (= end (length output))    ; No more lines in output
  1449.         (setq continue nil)        ;  so we can exit the filter.
  1450.       (setq start end))))))        ; else move start to next line of input
  1451.  
  1452.  
  1453. ;;; This function destroys the mark location if it is in the word being
  1454. ;;; highlighted.
  1455. (defun ispell-highlight-spelling-error-generic (start end &optional highlight)
  1456.   "Highlight the word from START to END with a kludge using `inverse-video'.
  1457. When the optional third arg HIGHLIGHT is set, the word is highlighted;
  1458. otherwise it is displayed normally."
  1459.   (let ((modified (buffer-modified-p))    ; don't allow this fn to modify buffer
  1460.     (buffer-read-only nil)        ; Allow highlighting read-only buffers.
  1461.     (text (buffer-substring start end)) ; Save highlight region
  1462.     (inhibit-quit t)        ; inhibit interrupt processing here.
  1463.     (buffer-undo-list t))        ; don't clutter the undo list.
  1464.     (delete-region start end)
  1465.     (insert-char ?  (- end start))    ; minimize amount of redisplay
  1466.     (sit-for 0)                ; update display
  1467.     (if highlight (setq inverse-video (not inverse-video))) ; toggle video
  1468.     (delete-region start end)        ; delete whitespace
  1469.     (insert text)            ; insert text in inverse video.
  1470.     (sit-for 0)                ; update display showing inverse video.
  1471.     (if highlight (setq inverse-video (not inverse-video))) ; toggle video
  1472.     (set-buffer-modified-p modified)))    ; don't modify if flag not set.
  1473.  
  1474.  
  1475. (defun ispell-highlight-spelling-error-lucid (start end &optional highlight)
  1476.   "Highlight the word from START to END using `isearch-highlight'.
  1477. When the optional third arg HIGHLIGHT is set, the word is highlighted,
  1478. otherwise it is displayed normally."
  1479.   (if highlight
  1480.       (isearch-highlight start end)
  1481.     (isearch-dehighlight t))
  1482.   ;;(sit-for 0)
  1483.   )
  1484.  
  1485.  
  1486. (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
  1487.   "Highlight the word from START to END using overlays.
  1488. When the optional third arg HIGHLIGHT is set, the word is highlighted
  1489. otherwise it is displayed normally.
  1490.  
  1491. The variable `ispell-highlight-face' selects the face to use for highlighting."
  1492.   (if highlight
  1493.       (progn
  1494.     (setq ispell-overlay (make-overlay start end))
  1495.     (overlay-put ispell-overlay 'face ispell-highlight-face))
  1496.     (delete-overlay ispell-overlay)))
  1497.  
  1498.  
  1499. (defun ispell-highlight-spelling-error (start end &optional highlight)
  1500.   (cond
  1501.    ((string-match "Lucid" emacs-version)
  1502.     (ispell-highlight-spelling-error-lucid start end highlight))
  1503.    ((and (string-lessp "19" emacs-version)
  1504.      (featurep 'faces) window-system)
  1505.     (ispell-highlight-spelling-error-overlay start end highlight))
  1506.    (t (ispell-highlight-spelling-error-generic start end highlight))))
  1507.  
  1508.  
  1509. (defun ispell-overlay-window (height)
  1510.   "Create a window covering the top HEIGHT lines of the current window.
  1511. Ensure that the line above point is still visible but otherwise avoid
  1512. scrolling the current window.  Leave the new window selected."
  1513.   (save-excursion
  1514.     (let ((oldot (save-excursion (forward-line -1) (point)))
  1515.       (top (save-excursion (move-to-window-line height) (point))))
  1516.       ;; If line above old point (line starting at olddot) would be
  1517.       ;; hidden by new window, scroll it to just below new win
  1518.       ;; otherwise set top line of other win so it doesn't scroll.
  1519.       (if (< oldot top) (setq top oldot))
  1520.       ;; NB: Lemacs 19.9 bug: If a window of size N (N includes the mode
  1521.       ;; line) is demanded, the last line is not visible.
  1522.       ;; At least this happens on AIX 3.2, lemacs w/ Motif, font 9x15.
  1523.       ;; So we increment the height for this case.
  1524.       (if (string-match "19\.9.*Lucid" (emacs-version))
  1525.       (setq height (1+ height)))
  1526.       (split-window nil height)
  1527.       (set-window-start (next-window) top))))
  1528.  
  1529.  
  1530. ;;; Should we add a compound word match return value?
  1531. (defun ispell-parse-output (output)
  1532.   "Parse the OUTPUT string from Ispell and return:
  1533. 1: t for an exact match.
  1534. 2: A string containing the root word for a match via suffix removal.
  1535. 3: A list of possible correct spellings of the format:
  1536.    '(\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
  1537.    ORIGINAL-WORD is a string of the possibly misspelled word.
  1538.    OFFSET is an integer giving the line offset of the word.
  1539.    MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses."
  1540.   (cond
  1541.    ((string= output "") t)        ; for startup with pipes...
  1542.    ((string= output "*") t)        ; exact match
  1543.    ((string= output "-") t)             ; compound word match
  1544.    ((string= (substring output 0 1) "+") ; found cuz of root word
  1545.     (substring output 2))        ; return root word
  1546.    (t                    ; need to process &, ?, and #'s
  1547.     (let ((type (substring output 0 1))    ; &, ?, or #
  1548.       (original-word (substring output 2 (string-match " " output 2)))
  1549.       (cur-count 0)            ; contains number of misses + guesses
  1550.       count miss-list guess-list offset)
  1551.       (setq output (substring output (match-end 0))) ; skip over misspelling
  1552.       (if (string= type "#")
  1553.       (setq count 0)        ; no misses for type #
  1554.     (setq count (string-to-int output) ; get number of misses.
  1555.           output (substring output (1+ (string-match " " output 1)))))
  1556.       (setq offset (string-to-int output))
  1557.       (if (string= type "#")        ; No miss or guess list.
  1558.       (setq output nil)
  1559.     (setq output (substring output (1+ (string-match " " output 1)))))
  1560.       (while output
  1561.     (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
  1562.       (setq cur-count (1+ cur-count))
  1563.       (if (> cur-count count)
  1564.           (setq guess-list (cons (substring output 0 end) guess-list))
  1565.         (setq miss-list (cons (substring output 0 end) miss-list)))
  1566.       (if (match-end 1)        ; True only when at end of line.
  1567.           (setq output nil)        ; no more misses or guesses
  1568.         (setq output (substring output (+ end 2))))))
  1569.       (list original-word offset miss-list guess-list)))))
  1570.  
  1571.  
  1572. (defun check-ispell-version ()
  1573.   ;; This is a little wasteful as we actually launch ispell twice: once
  1574.   ;; to make sure it's the right version, and once for real.  But people
  1575.   ;; get confused by version mismatches *all* the time (and I've got the
  1576.   ;; email to prove it) so I think this is worthwhile.  And the -v[ersion]
  1577.   ;; option is the only way I can think of to do this that works with
  1578.   ;; all versions, since versions earlier than 3.0.09 didn't identify
  1579.   ;; themselves on startup.
  1580.   (save-excursion
  1581.     (let ((case-fold-search t)
  1582.       ;; avoid bugs when syntax of `.' changes in various default modes
  1583.       (default-major-mode 'fundamental-mode)
  1584.       status)
  1585.       (set-buffer (get-buffer-create " *ispell-tmp*"))
  1586.       (erase-buffer)
  1587.       (setq status (call-process ispell-program-name nil t nil "-v"))
  1588.       (goto-char (point-min))
  1589.       (if (not (memq status '(0 nil)))
  1590.       (error "%s exited with %s %s" ispell-program-name
  1591.          (if (stringp status) "signal" "code") status))
  1592.       (if (not (re-search-forward
  1593.         (concat "\\b\\("
  1594.             (regexp-quote (car ispell-required-version))
  1595.             "\\)\\([0-9]*\\)\\b")
  1596.         nil t))
  1597.       (error
  1598.        "%s version %s* is required: try renaming ispell4.el to ispell.el"
  1599.        ispell-program-name (car ispell-required-version))
  1600.     ;; check that it is the correct version.
  1601.     (if (< (car (read-from-string (buffer-substring
  1602.                        (match-beginning 2) (match-end 2))))
  1603.            (car (cdr ispell-required-version)))
  1604.         (setq ispell-offset 0)))
  1605.       (kill-buffer (current-buffer)))))
  1606.  
  1607.  
  1608. (defun ispell-init-process ()
  1609.   "Check status of Ispell process and start if necessary."
  1610.   (if (and ispell-process
  1611.        (eq (process-status ispell-process) 'run)
  1612.        ;; If we're using a personal dictionary, assure
  1613.        ;; we're in the same default directory!
  1614.        (or (not ispell-personal-dictionary)
  1615.            (equal ispell-process-directory default-directory)))
  1616.       (setq ispell-filter nil ispell-filter-continue nil)
  1617.     ;; may need to restart to select new personal dictionary.
  1618.     (ispell-kill-ispell t)
  1619.     (message "Starting new Ispell process...")
  1620.     (sit-for 0)
  1621.     (check-ispell-version)
  1622.     (setq ispell-process
  1623.       (let ((process-connection-type ispell-use-ptys-p))
  1624.         (apply 'start-process
  1625.            "ispell" nil ispell-program-name
  1626.            "-a"            ; accept single input lines
  1627.            "-m"            ; make root/affix combos not in dict
  1628.            (let (args)
  1629.              ;; Local dictionary becomes the global dictionary in use.
  1630.              (if ispell-local-dictionary
  1631.              (setq ispell-dictionary ispell-local-dictionary))
  1632.              (setq args (ispell-get-ispell-args))
  1633.              (if ispell-dictionary ; use specified dictionary
  1634.              (setq args
  1635.                    (append (list "-d" ispell-dictionary) args)))
  1636.              (if ispell-personal-dictionary ; use specified pers dict
  1637.              (setq args
  1638.                    (append args
  1639.                        (list "-p"
  1640.                          (expand-file-name
  1641.                           ispell-personal-dictionary)))))
  1642.              (setq args (append args ispell-extra-args))
  1643.              args)))
  1644.       ispell-filter nil
  1645.       ispell-filter-continue nil
  1646.       ispell-process-directory default-directory)
  1647.     (set-process-filter ispell-process 'ispell-filter)
  1648.     (if ispell-dictionary
  1649.     (set-process-coding-system ispell-process (ispell-get-coding-system)))
  1650.     (accept-process-output ispell-process) ; Get version ID line
  1651.     (cond ((null ispell-filter)
  1652.        (error "%s did not output version line" ispell-program-name))
  1653.       ((and
  1654.         (stringp (car ispell-filter))
  1655.         (if (string-match "warning: " (car ispell-filter))
  1656.         (progn
  1657.           (accept-process-output ispell-process 5) ; 1st was warn msg.
  1658.           (stringp (car ispell-filter)))
  1659.           (null (cdr ispell-filter)))
  1660.         (string-match "^@(#) " (car ispell-filter)))
  1661.        ;; got the version line as expected (we already know it's the right
  1662.        ;; version, so don't bother checking again.)
  1663.        nil)
  1664.       (t
  1665.        ;; Otherwise, it must be an error message.  Show the user.
  1666.        ;; But first wait to see if some more output is going to arrive.
  1667.        ;; Otherwise we get cool errors like "Can't open ".
  1668.        (sleep-for 1)
  1669.        (accept-process-output)
  1670.        (error "%s" (mapconcat 'identity ispell-filter "\n"))))
  1671.     (setq ispell-filter nil)        ; Discard version ID line
  1672.     (let ((extended-char-mode (ispell-get-extended-character-mode)))
  1673.       (if extended-char-mode
  1674.       (process-send-string ispell-process
  1675.                    (concat extended-char-mode "\n"))))
  1676.     (process-kill-without-query ispell-process)))
  1677.  
  1678. ;;;###autoload
  1679. (defun ispell-kill-ispell (&optional no-error)
  1680.   "Kill current Ispell process (so that you may start a fresh one).
  1681. With NO-ERROR, just return non-nil if there was no Ispell running."
  1682.   (interactive)
  1683.   (if (not (and ispell-process
  1684.         (eq (process-status ispell-process) 'run)))
  1685.       (or no-error
  1686.       (error "There is no ispell process running!"))
  1687.     (kill-process ispell-process)
  1688.     (setq ispell-process nil)
  1689.     (message "Ispell process killed")
  1690.     nil))
  1691.  
  1692.  
  1693. ;;; ispell-change-dictionary is set in some people's hooks.  Maybe this should
  1694. ;;;  call ispell-init-process rather than wait for a spell checking command?
  1695.  
  1696. ;;;###autoload
  1697. (defun ispell-change-dictionary (dict &optional arg)
  1698.   "Change `ispell-dictionary' (q.v.) and kill old Ispell process.
  1699. A new one will be started as soon as necessary.
  1700.  
  1701. By just answering RET you can find out what the current dictionary is.
  1702.  
  1703. With prefix argument, set the default directory."
  1704.   (interactive
  1705.    (list (completing-read
  1706.       "Use new dictionary (RET for current, SPC to complete): "
  1707.       (cons (cons "default" nil) ispell-dictionary-alist) nil t)
  1708.      current-prefix-arg))
  1709.   (if (equal dict "default") (setq dict nil))
  1710.   ;; This relies on completing-read's bug of returning "" for no match
  1711.   (cond ((equal dict "")
  1712.      (message "Using %s dictionary"
  1713.           (or ispell-local-dictionary ispell-dictionary "default")))
  1714.     ((and (equal dict ispell-dictionary)
  1715.           (or (null ispell-local-dictionary)
  1716.           (equal dict ispell-local-dictionary)))
  1717.      ;; Specified dictionary is the default already.  No-op
  1718.      (and (interactive-p)
  1719.           (message "No change, using %s dictionary" (or dict "default"))))
  1720.     (t                ; reset dictionary!
  1721.      (if (assoc dict ispell-dictionary-alist)
  1722.          (progn
  1723.            (if (or arg (null dict))    ; set default dictionary
  1724.            (setq ispell-dictionary dict))
  1725.            (if (null arg)        ; set local dictionary
  1726.            (setq ispell-local-dictionary dict)))
  1727.        (error "Illegal dictionary: %s" dict))
  1728.      (ispell-kill-ispell t)
  1729.      (message "(Next %sIspell command will use %s dictionary)"
  1730.           (cond ((equal ispell-local-dictionary ispell-dictionary)
  1731.              "")
  1732.             (arg "global ")
  1733.             (t "local "))
  1734.           (or (if (or (equal ispell-local-dictionary ispell-dictionary)
  1735.                   (null arg))
  1736.               ispell-local-dictionary
  1737.             ispell-dictionary)
  1738.               "default")))))
  1739.  
  1740.  
  1741. ;;; Spelling of comments are checked when ispell-check-comments is non-nil.
  1742.  
  1743. ;;;###autoload
  1744. (defun ispell-region (reg-start reg-end)
  1745.   "Interactively check a region for spelling errors."
  1746.   (interactive "r")            ; Don't flag errors on read-only bufs.
  1747.   (ispell-accept-buffer-local-defs)    ; set up dictionary, local words, etc.
  1748.   (unwind-protect
  1749.       (save-excursion
  1750.     (message "Spell checking %s using %s dictionary..."
  1751.          (if (and (= reg-start (point-min)) (= reg-end (point-max)))
  1752.              (buffer-name) "region")
  1753.          (or ispell-dictionary "default"))
  1754.     ;; Returns cursor to original location.
  1755.     (save-window-excursion
  1756.       (goto-char reg-start)
  1757.       (let ((transient-mark-mode nil)
  1758.         ref-type)
  1759.         (while (and (not ispell-quit) (< (point) reg-end))
  1760.           (let ((start (point))
  1761.             (offset-change 0)
  1762.             (end (save-excursion (end-of-line) (min (point) reg-end)))
  1763.             (ispell-casechars (ispell-get-casechars))
  1764.             string)
  1765.         (cond            ; LOOK AT THIS LINE AND SKIP OR PROCESS
  1766.          ((eolp)        ; END OF LINE, just go to next line.
  1767.           (forward-char 1))
  1768.          ((and (null ispell-check-comments) ; SKIPPING COMMENTS
  1769.                comment-start    ; skip comments that start on the line.
  1770.                (search-forward comment-start end t)) ; or found here.
  1771.           (if (= (- (point) start) (length comment-start))
  1772.               ;; comment starts the line.  Skip entire line or region
  1773.               (if (string= "" comment-end) ; skip to next line
  1774.               (beginning-of-line 2)    ; or jump to comment end.
  1775.             (search-forward comment-end reg-end 'limit))
  1776.             ;; Comment later in line.  Check spelling before comment.
  1777.             (let ((limit (- (point) (length comment-start))))
  1778.               (goto-char (1- limit))
  1779.               (if (looking-at "\\\\") ; "quoted" comment, don't skip
  1780.               ;; quoted comment.  Skip over comment-start
  1781.               (if (= start (1- limit))
  1782.                   (setq limit (+ limit (length comment-start)))
  1783.                 (setq limit (1- limit))))
  1784.               (goto-char start)
  1785.               ;; Only check when "casechars" or math before comment
  1786.               (if (or (re-search-forward ispell-casechars limit t)
  1787.                   (re-search-forward "[][()$]" limit t))
  1788.               (setq string
  1789.                 (concat "^" (buffer-substring start limit)
  1790.                     "\n")
  1791.                 offset-change (- offset-change ispell-offset)))
  1792.               (goto-char limit))))
  1793.          ((looking-at "[---#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
  1794.           (forward-char 1))
  1795.          ((or (and ispell-skip-tib ; SKIP TIB REFERENCES OR SGML MARKUP
  1796.                (re-search-forward ispell-tib-ref-beginning end t)
  1797.                (setq ref-type 'tib))
  1798.               (and ispell-skip-sgml
  1799.                (re-search-forward "[<&]" end t)
  1800.                (setq ref-type 'sgml)))
  1801.           (if (or (and (eq 'tib ref-type) ; tib tag is 2 chars.
  1802.                    (= (- (point) 2) start))
  1803.               (and (eq 'sgml ref-type) ; sgml skips 1 char.
  1804.                    (= (- (point) 1) start)))
  1805.               ;; Skip to end of reference, not necessarily on this line
  1806.               ;; Return an error if tib/sgml reference not found
  1807.               (if (or
  1808.                (and
  1809.                 (eq 'tib ref-type)
  1810.                 (not
  1811.                  (re-search-forward ispell-tib-ref-end reg-end t)))
  1812.                (and (eq 'sgml ref-type)
  1813.                 (not (re-search-forward "[>;]" reg-end t))))
  1814.               (progn
  1815.                 (ispell-pdict-save ispell-silently-savep)
  1816.                 (ding)
  1817.                 (message
  1818.                  (concat
  1819.                   "Open tib or SGML command.  Fix buffer or set "
  1820.                   (if (eq 'tib ref-type)
  1821.                   "ispell-skip-tib"
  1822.                 "ispell-skip-sgml")
  1823.                   " to nil"))
  1824.                 ;; keep cursor at error location
  1825.                 (setq ispell-quit (- (point) 2))))
  1826.             ;; Check spelling between reference and start of the line.
  1827.             (let ((limit (- (point) (if (eq 'tib ref-type) 2 1))))
  1828.               (goto-char start)
  1829.               (if (or (re-search-forward ispell-casechars limit t)
  1830.                   (re-search-forward "[][()$]" limit t))
  1831.               (setq string
  1832.                 (concat "^" (buffer-substring start limit)
  1833.                     "\n")
  1834.                 offset-change (- offset-change ispell-offset)))
  1835.               (goto-char limit))))
  1836.          ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
  1837.               (re-search-forward "[][()$]" end t)) ; or MATH COMMANDS
  1838.           (setq string (concat "^" (buffer-substring start end) "\n")
  1839.             offset-change (- offset-change ispell-offset))
  1840.           (goto-char end))
  1841.          (t (beginning-of-line 2))) ; EMPTY LINE, skip it.
  1842.  
  1843.         (setq end (point))    ; "end" tracks end of region to check.
  1844.  
  1845.         (if string        ; there is something to spell!
  1846.             (let (poss)
  1847.               ;; send string to spell process and get input.
  1848.               (process-send-string ispell-process string)
  1849.               (while (progn
  1850.                    (accept-process-output ispell-process)
  1851.                    ;; Last item of output contains a blank line.
  1852.                    (not (string= "" (car ispell-filter)))))
  1853.               ;; parse all inputs from the stream one word at a time.
  1854.               ;; Place in FIFO order and remove the blank item.
  1855.               (setq ispell-filter (nreverse (cdr ispell-filter)))
  1856.               (while (and (not ispell-quit) ispell-filter)
  1857.             (setq poss (ispell-parse-output (car ispell-filter)))
  1858.             (if (listp poss) ; spelling error occurred.
  1859.                 (let* ((word-start (+ start offset-change
  1860.                           (car (cdr poss))))
  1861.                    (word-end (+ word-start
  1862.                         (length (car poss))))
  1863.                    replace)
  1864.                   (goto-char word-start)
  1865.                   ;; Adjust the horizontal scroll & point
  1866.                   (ispell-horiz-scroll)
  1867.                   (goto-char word-end)
  1868.                   (ispell-horiz-scroll)
  1869.                   (goto-char word-start)
  1870.                   (ispell-horiz-scroll)
  1871.                   (if (/= word-end
  1872.                       (progn
  1873.                     (search-forward (car poss) word-end t)
  1874.                     (point)))
  1875.                   ;; This occurs due to filter pipe problems
  1876.                   (error
  1877.                    (concat "Ispell misalignment: word "
  1878.                        "`%s' point %d; please retry")
  1879.                    (car poss) word-start))
  1880.                   (if (not (pos-visible-in-window-p))
  1881.                   (sit-for 0))
  1882.                   (if ispell-keep-choices-win
  1883.                   (setq replace
  1884.                     (ispell-command-loop
  1885.                      (car (cdr (cdr poss)))
  1886.                      (car (cdr (cdr (cdr poss))))
  1887.                      (car poss) word-start word-end))
  1888.                 (save-window-excursion
  1889.                   (setq replace
  1890.                     (ispell-command-loop
  1891.                      (car (cdr (cdr poss)))
  1892.                      (car (cdr (cdr (cdr poss))))
  1893.                      (car poss) word-start word-end))))
  1894.                   (cond
  1895.                    ((and replace (listp replace))
  1896.                 ;; REPLACEMENT WORD entered.  Recheck line
  1897.                 ;; starting with the replacement word.
  1898.                 (setq ispell-filter nil
  1899.                       string (buffer-substring word-start
  1900.                                    word-end))
  1901.                 (let ((change (- (length (car replace))
  1902.                          (length (car poss)))))
  1903.                   ;; adjust regions
  1904.                   (setq reg-end (+ reg-end change)
  1905.                     offset-change (+ offset-change
  1906.                              change)))
  1907.                 (if (not (equal (car replace) (car poss)))
  1908.                     (progn
  1909.                       (delete-region word-start word-end)
  1910.                       (insert (car replace))))
  1911.                 ;; I only need to recheck typed-in replacements
  1912.                 (if (not (eq 'query-replace
  1913.                          (car (cdr replace))))
  1914.                     (backward-char (length (car replace))))
  1915.                 (setq end (point)) ; reposition for recheck
  1916.                 ;; when second arg exists, query-replace, saving regions
  1917.                 (if (car (cdr replace))
  1918.                     (unwind-protect
  1919.                     (save-window-excursion
  1920.                       (set-marker
  1921.                        ispell-query-replace-marker reg-end)
  1922.                       ;; Assume case-replace &
  1923.                       ;; case-fold-search correct?
  1924.                       (query-replace string (car replace)
  1925.                              t))
  1926.                       (setq reg-end
  1927.                         (marker-position
  1928.                          ispell-query-replace-marker))
  1929.                       (set-marker ispell-query-replace-marker
  1930.                           nil))))
  1931.                    ((or (null replace)
  1932.                     (equal 0 replace)) ; ACCEPT/INSERT
  1933.                 (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
  1934.                     (setq reg-end
  1935.                       (ispell-add-per-file-word-list
  1936.                        (car poss) reg-end)))
  1937.                 ;; This avoids pointing out the word that was
  1938.                 ;; just accepted (via 'i' or 'a') if it follows
  1939.                 ;; on the same line.
  1940.                 ;; Redo check following the accepted word.
  1941.                 (if (and ispell-pdict-modified-p
  1942.                      (listp ispell-pdict-modified-p))
  1943.                     ;; Word accepted.  Recheck line.
  1944.                     (setq ispell-pdict-modified-p ; update flag
  1945.                       (car ispell-pdict-modified-p)
  1946.                       ispell-filter nil ; discontinue check
  1947.                       end word-start))) ; reposition loc.
  1948.                    (replace    ; STRING REPLACEMENT for this word.
  1949.                 (delete-region word-start word-end)
  1950.                 (insert replace)
  1951.                 (let ((change (- (length replace)
  1952.                          (length (car poss)))))
  1953.                   (setq reg-end (+ reg-end change)
  1954.                     offset-change (+ offset-change change)
  1955.                     end (+ end change)))))
  1956.                   (if (not ispell-quit)
  1957.                   (display-message 'command
  1958.                     "Continuing spelling check using %s dictionary..."
  1959.                     (or ispell-dictionary "default")))
  1960.                   (sit-for 0)))
  1961.             ;; finished with line!
  1962.             (setq ispell-filter (cdr ispell-filter)))))
  1963.         (goto-char end)))))
  1964.     (not ispell-quit))
  1965.     ;; protected
  1966.     (if (get-buffer ispell-choices-buffer)
  1967.     (kill-buffer ispell-choices-buffer))
  1968.     (if ispell-quit
  1969.     (progn
  1970.       ;; preserve or clear the region for ispell-continue.
  1971.       (if (not (numberp ispell-quit))
  1972.           (set-marker ispell-region-end nil)
  1973.         ;; Enable ispell-continue.
  1974.         (set-marker ispell-region-end reg-end)
  1975.         (goto-char ispell-quit))
  1976.       ;; Check for aborting
  1977.       (if (and ispell-checking-message (numberp ispell-quit))
  1978.           (progn
  1979.         (setq ispell-quit nil)
  1980.         (error "Message send aborted.")))
  1981.       (setq ispell-quit nil))
  1982.       (set-marker ispell-region-end nil)
  1983.       ;; Only save if successful exit.
  1984.       (ispell-pdict-save ispell-silently-savep)
  1985.       (message "Spell-checking done"))))
  1986.  
  1987.  
  1988.  
  1989. ;;;###autoload
  1990. (defun ispell-buffer ()
  1991.   "Check the current buffer for spelling errors interactively."
  1992.   (interactive)
  1993.   (ispell-region (point-min) (point-max)))
  1994.  
  1995.  
  1996. ;;;###autoload
  1997. (defun ispell-continue ()
  1998.   (interactive)
  1999.   "Continue a spelling session after making some changes."
  2000.   (if (not (marker-position ispell-region-end))
  2001.       (message "No session to continue.  Use 'X' command when checking!")
  2002.     (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
  2003.     (message "Must continue ispell from buffer %s"
  2004.          (buffer-name (marker-buffer ispell-region-end)))
  2005.       (ispell-region (point) (marker-position ispell-region-end)))))
  2006.  
  2007.  
  2008. ;;; Horizontal scrolling
  2009. (defun ispell-horiz-scroll ()
  2010.   "Places point within the horizontal visibility of its window area."
  2011.   (if truncate-lines            ; display truncating lines?
  2012.       ;; See if display needs to be scrolled.
  2013.       (let ((column (- (current-column) (max (window-hscroll) 1))))
  2014.     (if (and (< column 0) (> (window-hscroll) 0))
  2015.         (scroll-right (max (- column) 10))
  2016.       (if (>= column (- (window-width) 2))
  2017.           (scroll-left (max (- column (window-width) -3) 10)))))))
  2018.  
  2019.  
  2020. ;;; Interactive word completion.
  2021. ;;; Forces "previous-word" processing.  Do we want to make this selectable?
  2022.  
  2023. ;;;###autoload
  2024. (defun ispell-complete-word (&optional interior-frag)
  2025.   "Look up word before or under point in dictionary (see lookup-words command)
  2026. and try to complete it.  If optional INTERIOR-FRAG is non-nil then the word
  2027. may be a character sequence inside of a word.
  2028.  
  2029. Standard ispell choices are then available."
  2030.   (interactive "P")
  2031.   (let ((cursor-location (point))
  2032.     case-fold-search
  2033.     (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
  2034.     start end possibilities replacement)
  2035.     (setq start (car (cdr word))
  2036.       end (car (cdr (cdr word)))
  2037.       word (car word)
  2038.       possibilities
  2039.       (or (string= word "")        ; Will give you every word
  2040.           (lookup-words (concat (if interior-frag "*") word "*")
  2041.                 ispell-complete-word-dict)))
  2042.     (cond ((eq possibilities t)
  2043.        (message "No word to complete"))
  2044.       ((null possibilities)
  2045.        (message "No match for \"%s\"" word))
  2046.       (t                ; There is a modification...
  2047.        (cond            ; Try and respect case of word.
  2048.         ((string-match "^[^A-Z]+$" word)
  2049.          (setq possibilities (mapcar 'downcase possibilities)))
  2050.         ((string-match "^[^a-z]+$" word)
  2051.          (setq possibilities (mapcar 'upcase possibilities)))
  2052.         ((string-match "^[A-Z]" word)
  2053.          (setq possibilities (mapcar 'capitalize possibilities))))
  2054.        (save-window-excursion
  2055.          (setq replacement
  2056.            (ispell-command-loop possibilities nil word start end)))
  2057.        (cond
  2058.         ((equal 0 replacement)    ; BUFFER-LOCAL ADDITION
  2059.          (ispell-add-per-file-word-list word))
  2060.         (replacement        ; REPLACEMENT WORD
  2061.          (delete-region start end)
  2062.          (setq word (if (atom replacement) replacement (car replacement))
  2063.            cursor-location (+ (- (length word) (- end start))
  2064.                       cursor-location))
  2065.          (insert word)
  2066.          (if (not (atom replacement)) ; recheck spelling of replacement.
  2067.          (progn
  2068.            (goto-char cursor-location)
  2069.            (ispell-word nil t)))))
  2070.        (if (get-buffer ispell-choices-buffer)
  2071.            (kill-buffer ispell-choices-buffer))))
  2072.     (ispell-pdict-save ispell-silently-savep)
  2073.     (goto-char cursor-location)))
  2074.  
  2075.  
  2076. ;;;###autoload
  2077. (defun ispell-complete-word-interior-frag ()
  2078.   "Completes word matching character sequence inside a word."
  2079.   (interactive)
  2080.   (ispell-complete-word t))
  2081.  
  2082.  
  2083. ;;; **********************************************************************
  2084. ;;;             Ispell Minor Mode
  2085. ;;; **********************************************************************
  2086.  
  2087. (defvar ispell-minor-mode nil
  2088.   "Non-nil if Ispell minor mode is enabled.")
  2089. ;; Variable indicating that ispell minor mode is active.
  2090. (make-variable-buffer-local 'ispell-minor-mode)
  2091.  
  2092. (or (assq 'ispell-minor-mode minor-mode-alist)
  2093.     (setq minor-mode-alist
  2094.           (cons '(ispell-minor-mode " Spell") minor-mode-alist)))
  2095.  
  2096. (defvar ispell-minor-keymap
  2097.   (let ((map (make-sparse-keymap)))
  2098.     (define-key map " " 'ispell-minor-check)
  2099.     (define-key map "\r" 'ispell-minor-check)
  2100.     map)
  2101.   "Keymap used for Ispell minor mode.")
  2102.  
  2103. (or (not (boundp 'minor-mode-map-alist))
  2104.     (assoc 'ispell-minor-mode minor-mode-map-alist)
  2105.     (setq minor-mode-map-alist
  2106.           (cons (cons 'ispell-minor-mode ispell-minor-keymap)
  2107.                 minor-mode-map-alist)))
  2108.  
  2109. ;;;###autoload
  2110. (defun ispell-minor-mode (&optional arg)
  2111.   "Toggle Ispell minor mode.
  2112. With prefix arg, turn Ispell minor mode on iff arg is positive.
  2113.  
  2114. In Ispell minor mode, pressing SPC or RET
  2115. warns you if the previous word is incorrectly spelled."
  2116.   (interactive "P")
  2117.   (setq ispell-minor-mode
  2118.     (not (or (and (null arg) ispell-minor-mode)
  2119.          (<= (prefix-numeric-value arg) 0))))
  2120.   (redraw-modeline))
  2121.  
  2122. (defun ispell-minor-check ()
  2123.   ;; Check previous word then continue with the normal binding of this key.
  2124.   (interactive "*")
  2125.   (let ((ispell-minor-mode nil)
  2126.     (ispell-check-only t))
  2127.     (save-restriction
  2128.       (narrow-to-region (point-min) (point))
  2129.       (ispell-word nil t))
  2130.     (call-interactively (key-binding (this-command-keys)))))
  2131.  
  2132.  
  2133. ;;; **********************************************************************
  2134. ;;;             Ispell Message
  2135. ;;; **********************************************************************
  2136. ;;; Original from D. Quinlan, E. Bradford, A. Albert, and M. Ernst
  2137.  
  2138.  
  2139. (defvar ispell-message-text-end
  2140.   (mapconcat (function identity)
  2141.          '(
  2142.            ;; Matches postscript files.
  2143.            "^%!PS-Adobe-[123].0"
  2144.            ;; Matches uuencoded text
  2145.            "^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
  2146.            ;; Matches shell files (esp. auto-decoding)
  2147.            "^#! /bin/[ck]?sh"
  2148.            ;; Matches context difference listing
  2149.            "\\(diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
  2150.            ;; Matches reporter.el bug report
  2151.            "^current state:\n==============\n"
  2152.            ;; Matches "----------------- cut here"
  2153.            ;; and "------- Start of forwarded message"
  2154.            "^[-=_]+\\s ?\\(cut here\\|Start of forwarded message\\)")
  2155.          "\\|")
  2156.   "*End of text which will be checked in ispell-message.
  2157. If it is a string, limit at first occurrence of that regular expression.
  2158. Otherwise, it must be a function which is called to get the limit.")
  2159.  
  2160.  
  2161. (defvar ispell-message-start-skip
  2162.   (mapconcat (function identity)
  2163.          '(
  2164.            ;; Matches forwarded messages
  2165.            "^---* Forwarded Message"
  2166.            ;; Matches PGP Public Key block
  2167.            "^---*BEGIN PGP [A-Z ]*--*"
  2168.            )
  2169.          "\\|")
  2170.   "Spelling is skipped inside these start/end groups by ispell-message.
  2171. Assumed that blocks are not mutually inclusive.")
  2172.  
  2173.  
  2174. (defvar ispell-message-end-skip
  2175.   (mapconcat (function identity)
  2176.          '(
  2177.            ;; Matches forwarded messages
  2178.            "^--- End of Forwarded Message"
  2179.            ;; Matches PGP Public Key block
  2180.            "^---*END PGP [A-Z ]*--*"
  2181.            )
  2182.          "\\|")
  2183.   "Spelling is skipped inside these start/end groups by ispell-message.
  2184. Assumed that blocks are not mutually inclusive.")
  2185.  
  2186.  
  2187. ;;;###autoload
  2188. (defun ispell-message ()
  2189.   "Check the spelling of a mail message or news post.
  2190. Don't check spelling of message headers except the Subject field.
  2191. Don't check included messages.
  2192.  
  2193. To abort spell checking of a message region and send the message anyway,
  2194. use the `x' or `q' command.  (Any subsequent regions will be checked.)
  2195. The `X' command aborts the message send so that you can edit the buffer.
  2196.  
  2197. To spell-check whenever a message is sent, include the appropriate lines
  2198. in your .emacs file:
  2199.    (add-hook 'message-send-hook 'ispell-message)
  2200.    (add-hook 'mail-send-hook  'ispell-message)
  2201.    (add-hook 'mh-before-send-letter-hook 'ispell-message)
  2202.  
  2203. You can bind this to the key C-c i in GNUS or mail by adding to
  2204. `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
  2205.    (function (lambda () (local-set-key \"\\C-ci\" 'ispell-message)))"
  2206.   (interactive)
  2207.   (save-excursion
  2208.     (goto-char (point-min))
  2209.     (let* ((internal-messagep (save-excursion
  2210.                 (re-search-forward
  2211.                  (concat "^"
  2212.                      (regexp-quote mail-header-separator)
  2213.                      "$")
  2214.                  nil t)))
  2215.        (limit (copy-marker
  2216.            (cond
  2217.             ((not ispell-message-text-end) (point-max))
  2218.             ((char-or-string-p ispell-message-text-end)
  2219.              (if (re-search-forward ispell-message-text-end nil t)
  2220.              (match-beginning 0)
  2221.                (point-max)))
  2222.             (t (min (point-max) (funcall ispell-message-text-end))))))
  2223.        (cite-regexp            ;Prefix of inserted text
  2224.         (cond
  2225.          ((featurep 'supercite)    ; sc 3.0
  2226.           (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
  2227.               (ispell-non-empty-string sc-reference-tag-string)))
  2228.          ((featurep 'sc)        ; sc 2.3
  2229.           (concat "\\(" sc-cite-regexp "\\)" "\\|"
  2230.               (ispell-non-empty-string sc-reference-tag-string)))
  2231.          ((equal major-mode 'news-reply-mode) ;GNUS 4 & below
  2232.           (concat "In article <" "\\|"
  2233.               (if mail-yank-prefix
  2234.               (ispell-non-empty-string mail-yank-prefix)
  2235.             "^   \\|^\t")))
  2236.          ((equal major-mode 'message-mode) ;GNUS 5
  2237.           (concat ".*@.* writes:$" "\\|"
  2238.               (if mail-yank-prefix
  2239.               (ispell-non-empty-string mail-yank-prefix)
  2240.             "^   \\|^\t")))
  2241.          ((equal major-mode 'mh-letter-mode) ; mh mail message
  2242.           (ispell-non-empty-string mh-ins-buf-prefix))
  2243.          ((not internal-messagep)    ; Assume n sent us this message.
  2244.           (concat "In [a-zA-Z.]+ you write:" "\\|"
  2245.               "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
  2246.               " *> *"))
  2247.          ((boundp 'vm-included-text-prefix) ; VM mail message
  2248.           (concat "[^,;&+=]+ writes:" "\\|"
  2249.               (ispell-non-empty-string vm-included-text-prefix)))
  2250.          (mail-yank-prefix        ; vanilla mail message.
  2251.           (ispell-non-empty-string mail-yank-prefix))
  2252.          (t "^   \\|^\t")))
  2253.        (cite-regexp-start (concat "^[ \t]*$\\|" cite-regexp))
  2254.        (cite-regexp-end   (concat "^\\(" cite-regexp "\\)"))
  2255.        (old-case-fold-search case-fold-search)
  2256.        (case-fold-search t)
  2257.        (ispell-checking-message t))
  2258.       (goto-char (point-min))
  2259.       ;; Skip header fields except Subject: without Re:'s
  2260.       ;;(search-forward mail-header-separator nil t)
  2261.       (while (if internal-messagep
  2262.          (< (point) internal-messagep)
  2263.            (and (looking-at "[a-zA-Z---]+:\\|\t\\| ")
  2264.             (not (eobp))))
  2265.     (if (looking-at "Subject: *")    ; Spell check new subject fields
  2266.         (progn
  2267.           (goto-char (match-end 0))
  2268.           (if (and (not (looking-at ".*Re\\>"))
  2269.                (not (looking-at "\\[")))
  2270.           (let ((case-fold-search old-case-fold-search))
  2271.             (ispell-region (point)
  2272.                    (progn
  2273.                      (end-of-line)
  2274.                      (while (looking-at "\n[ \t]")
  2275.                        (end-of-line 2))
  2276.                      (point)))))))
  2277.     (forward-line 1))
  2278.       (setq case-fold-search nil)
  2279.       ;; Skip mail header, particularly for non-english languages.
  2280.       (if (looking-at (concat (regexp-quote mail-header-separator) "$"))
  2281.       (forward-line 1))
  2282.       (while (< (point) limit)
  2283.     ;; Skip across text cited from other messages.
  2284.     (while (and (looking-at cite-regexp-start)
  2285.             (< (point) limit)
  2286.             (zerop (forward-line 1))))
  2287.  
  2288.     (if (< (point) limit)
  2289.         (let* ((start (point))
  2290.            ;; Check the next batch of lines that *aren't* cited.
  2291.            (end-c (and (re-search-forward cite-regexp-end limit 'end)
  2292.                    (match-beginning 0)))
  2293.            ;; Skip a block of included text.
  2294.            (end-fwd (and (goto-char start)
  2295.                  (re-search-forward ispell-message-start-skip
  2296.                             limit 'end)
  2297.                  (progn (beginning-of-line)
  2298.                     (point))))
  2299.            (end (or (and end-c end-fwd (min end-c end-fwd))
  2300.                 end-c end-fwd
  2301.                 ;; default to limit of text.
  2302.                 (marker-position limit))))
  2303.           (goto-char start)
  2304.           (ispell-region start end)
  2305.           (if (and end-fwd (= end end-fwd))
  2306.           (progn
  2307.             (goto-char end)
  2308.             (re-search-forward ispell-message-end-skip limit 'end))
  2309.         (goto-char end)))))
  2310.       (set-marker limit nil))))
  2311.  
  2312.  
  2313. (defun ispell-non-empty-string (string)
  2314.   (if (or (not string) (string-equal string ""))
  2315.       "\\'\\`" ; An unmatchable string if string is null.
  2316.     (regexp-quote string)))
  2317.  
  2318.  
  2319. ;;; **********************************************************************
  2320. ;;;             Buffer Local Functions
  2321. ;;; **********************************************************************
  2322.  
  2323.  
  2324. (defun ispell-accept-buffer-local-defs ()
  2325.   "Load all buffer-local information, restarting ispell when necessary."
  2326.   (ispell-buffer-local-dict)        ; May kill ispell-process.
  2327.   (ispell-buffer-local-words)        ; Will initialize ispell-process.
  2328.   (ispell-buffer-local-parsing))
  2329.  
  2330.  
  2331. (defun ispell-buffer-local-parsing ()
  2332.   "Place Ispell into parsing mode for this buffer.
  2333. Overrides the default parsing mode.
  2334. Includes latex/nroff modes and extended character mode."
  2335.   ;; (ispell-init-process) must already be called.
  2336.   (process-send-string ispell-process "!\n") ; Put process in terse mode.
  2337.   ;; We assume all major modes with "tex-mode" in them should use latex parsing
  2338.   (if (or (and (eq ispell-parser 'use-mode-name)
  2339.            (string-match "[Tt][Ee][Xx]-mode" (symbol-name major-mode)))
  2340.       (eq ispell-parser 'tex))
  2341.       (process-send-string ispell-process "+\n") ; set ispell mode to tex
  2342.     (process-send-string ispell-process "-\n"))    ; set mode to normal (nroff)
  2343.   ;; Hard-wire test for SGML & HTML mode.
  2344.   (setq ispell-skip-sgml (memq major-mode '(sgml-mode html-mode)))
  2345.   ;; Set default extended character mode for given buffer, if any.
  2346.   (let ((extended-char-mode (ispell-get-extended-character-mode)))
  2347.     (if extended-char-mode
  2348.     (process-send-string ispell-process (concat extended-char-mode "\n"))))
  2349.   ;; Set buffer-local parsing mode and extended character mode, if specified.
  2350.   (save-excursion
  2351.     (goto-char (point-min))
  2352.     ;; Uses last valid definition
  2353.     (while (search-forward ispell-parsing-keyword nil t)
  2354.       (let ((end (save-excursion (end-of-line) (point)))
  2355.         (case-fold-search t)
  2356.         string)
  2357.     (while (re-search-forward " *\\([^ \"]+\\)" end t)
  2358.       ;; space separated definitions.
  2359.       (setq string (buffer-substring (match-beginning 1) (match-end 1)))
  2360.       (cond ((string-match "latex-mode" string)
  2361.          (process-send-string ispell-process "+\n~tex\n"))
  2362.         ((string-match "nroff-mode" string)
  2363.          (process-send-string ispell-process "-\n~nroff"))
  2364.         ((string-match "~" string) ; Set extended character mode.
  2365.          (process-send-string ispell-process (concat string "\n")))
  2366.         (t (message "Illegal Ispell Parsing argument!")
  2367.            (sit-for 2))))))))
  2368.  
  2369.  
  2370. ;;; Can kill the current ispell process
  2371.  
  2372. (defun ispell-buffer-local-dict ()
  2373.   "Initializes local dictionary.
  2374. When a dictionary is defined in the buffer (see variable
  2375. `ispell-dictionary-keyword'), it will override the local setting
  2376. from \\[ispell-change-dictionary].
  2377. Both should not be used to define a buffer-local dictionary."
  2378.   (save-excursion
  2379.     (goto-char (point-min))
  2380.     (let (end)
  2381.       ;; Override the local variable definition.
  2382.       ;; Uses last valid definition.
  2383.       (while (search-forward ispell-dictionary-keyword nil t)
  2384.     (setq end (save-excursion (end-of-line) (point)))
  2385.     (if (re-search-forward " *\\([^ \"]+\\)" end t)
  2386.         (setq ispell-local-dictionary
  2387.           (buffer-substring (match-beginning 1) (match-end 1)))))
  2388.       (goto-char (point-min))
  2389.       (while (search-forward ispell-pdict-keyword nil t)
  2390.     (setq end (save-excursion (end-of-line) (point)))
  2391.     (if (re-search-forward " *\\([^ \"]+\\)" end t)
  2392.         (setq ispell-local-pdict
  2393.           (buffer-substring (match-beginning 1) (match-end 1)))))))
  2394.   ;; Reload if new personal dictionary defined.
  2395.   (if (and ispell-local-pdict
  2396.        (not (equal ispell-local-pdict ispell-personal-dictionary)))
  2397.       (progn
  2398.     (ispell-kill-ispell t)
  2399.     (setq ispell-personal-dictionary ispell-local-pdict)))
  2400.   ;; Reload if new dictionary defined.
  2401.   (if (and ispell-local-dictionary
  2402.        (not (equal ispell-local-dictionary ispell-dictionary)))
  2403.       (ispell-change-dictionary ispell-local-dictionary)))
  2404.  
  2405.  
  2406. (defun ispell-buffer-local-words ()
  2407.   "Loads the buffer-local dictionary in the current buffer."
  2408.   (if (and ispell-buffer-local-name
  2409.        (not (equal ispell-buffer-local-name (buffer-name))))
  2410.       (progn
  2411.     (ispell-kill-ispell t)
  2412.     (setq ispell-buffer-local-name nil)))
  2413.   (ispell-init-process)
  2414.   (save-excursion
  2415.     (goto-char (point-min))
  2416.     (while (search-forward ispell-words-keyword nil t)
  2417.       (or ispell-buffer-local-name
  2418.       (setq ispell-buffer-local-name (buffer-name)))
  2419.       (let ((end (save-excursion (end-of-line) (point)))
  2420.         string)
  2421.     ;; buffer-local words separated by a space, and can contain
  2422.     ;; any character other than a space.
  2423.     (while (re-search-forward " *\\([^ ]+\\)" end t)
  2424.       (setq string (buffer-substring (match-beginning 1) (match-end 1)))
  2425.       (process-send-string ispell-process (concat "@" string "\n")))))))
  2426.  
  2427.  
  2428. ;;; returns optionally adjusted region-end-point.
  2429.  
  2430. (defun ispell-add-per-file-word-list (word &optional reg-end)
  2431.   "Adds new word to the per-file word list."
  2432.   (or ispell-buffer-local-name
  2433.       (setq ispell-buffer-local-name (buffer-name)))
  2434.   (if (null reg-end)
  2435.       (setq reg-end 0))
  2436.   (save-excursion
  2437.     (goto-char (point-min))
  2438.     (let (case-fold-search line-okay search done string)
  2439.       (while (not done)
  2440.     (setq search (search-forward ispell-words-keyword nil 'move)
  2441.           line-okay (< (+ (length word) 1 ; 1 for space after word..
  2442.                   (progn (end-of-line) (current-column)))
  2443.                80))
  2444.     (if (or (and search line-okay)
  2445.         (null search))
  2446.         (progn
  2447.           (setq done t)
  2448.           (if (null search)
  2449.           (progn
  2450.             (open-line 1)
  2451.             (setq string (concat comment-start " "
  2452.                      ispell-words-keyword))
  2453.             ;; in case the keyword is in the middle of the file....
  2454.             (if (> reg-end (point))
  2455.             (setq reg-end (+ reg-end (length string))))
  2456.             (insert string)
  2457.             (if (and comment-end (not (equal "" comment-end)))
  2458.             (save-excursion
  2459.               (open-line 1)
  2460.               (forward-line 1)
  2461.               (insert comment-end)))))
  2462.           (if (> reg-end (point))
  2463.           (setq reg-end (+ 1 reg-end (length word))))
  2464.           (insert (concat " " word)))))))
  2465.   reg-end)
  2466.  
  2467.  
  2468. (defconst ispell-version "2.37 -- Tue Jun 13 12:05:28 EDT 1995")
  2469.  
  2470. (provide 'ispell)
  2471.  
  2472.  
  2473. ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
  2474.  
  2475. ;;; Local Variable options:
  2476. ;;; mode: name(-mode)
  2477. ;;; eval: expression
  2478. ;;; local-variable: value
  2479.  
  2480. ;;; The following sets the buffer local dictionary to english!
  2481.  
  2482. ;;; Local Variables:
  2483. ;;; mode: emacs-lisp
  2484. ;;; comment-column: 40
  2485. ;;; ispell-local-dictionary: "american"
  2486. ;;; End:
  2487.  
  2488.  
  2489. ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
  2490.  
  2491. ;;; The following places this file in nroff parsing and extended char modes.
  2492. ;;; Local IspellParsing: nroff-mode ~nroff
  2493. ;;; Change IspellDict to IspellDict: to enable the following line.
  2494. ;;; Local IspellDict english
  2495. ;;; Change IspellPersDict to IspellPersDict: to enable the following line.
  2496. ;;; Local IspellPersDict ~/.ispell_lisp
  2497. ;;; The following were automatically generated by ispell using the 'A' command:
  2498. ; LocalWords:  ispell ispell-highlight-p ispell-check-comments query-replace
  2499. ; LocalWords:  ispell-query-replace-choices ispell-skip-tib non-nil tib
  2500. ; LocalWords:  regexps ispell-tib-ref-beginning ispell-tib-ref-end
  2501.  
  2502. ;; ispell.el ends here
  2503.